JacksonDatabind, 65
<FILEB>
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: (%s) %s",
re.getClass().getName(), re.getMessage());
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
if (isFactoryMethod(am) && am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
if (am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
} else {
return null;
}
return new StdKeyDeserializer(kind, raw);
}
@Override
public Object deserializeKey(String key, DeserializationContext ctxt)
throws IOException
{
if (key == null) { // is this even legal call?
return null;
}
try {
Object result = _parse(key, ctxt);
if (result != null) {
return result;
}
} catch (Exception re) {
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: %s", re.getMessage());
<CHANGEE>
}
if (_keyClass.isEnum() && ctxt.getConfig().isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
return null;
}
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation");
}
public Class<?> getKeyClass() { return _keyClass; }
protected Object _parse(String key, DeserializationContext ctxt) throws Exception
{
switch (_kind) {
case TYPE_BOOLEAN:
if ("true".equals(key)) {
<FILEE>
<FILEB>
*/
if (ac.getParameterCount() == 1) {
Class<?> actArg = ac.getRawParameterType(0);
for (Class<?> expArg : argTypes) {
if (expArg == actArg) {
return ac.getAnnotated();
}
}
}
}
return null;
}
@Override
public Method findFactoryMethod(Class<?>... expArgTypes)
{
// So, of all single-arg static methods:
for (AnnotatedMethod am : _classInfo.getStaticMethods()) {
// 24-Oct-2016, tatu: Better ensure it only takes 1 arg, no matter what
<CHANGES>
if (isFactoryMethod(am)) {
<CHANGEE>
// And must take one of expected arg types (or supertype)
Class<?> actualArgType = am.getRawParameterType(0);
for (Class<?> expArgType : expArgTypes) {
// And one that matches what we would pass in
if (actualArgType.isAssignableFrom(expArgType)) {
return am.getAnnotated();
}
}
}
}
return null;
}
{
/* First: return<SCANS> instanceof Error) throw (Error) t;
if (t instanceof RuntimeException) throw (RuntimeException) t;
throw new IllegalArgumentException("Failed to instantiate bean of type "+_classInfo.getAnnotated().getName()+": ("+t.getClass().getName()+") "+t.getMessage(), t);
}
}
/*
/**********************************************************
/* Simple accessors, extended
/**********************************************************
*/
@Override
public AnnotatedMethod findMethod(String name, Class<?>[] paramTypes) {
return _classInfo.findMethod(name, paramTypes);
}
/*
/**********************************************************
/* General per-class annotation introspection
/**********************************************************
*/
@Override
public JsonFormat.Value findExpectedFormat(JsonFormat.Value defValue)
{
// 15-Apr-2016, tatu: Let's check both per-type defaults and annotations; per-type
// defaults having higher precedence, so start with that
if (_annotationIntrospector != null) {
JsonFormat.Value v = _annotationIntrospector.findFormat(_classInfo);
if (v != null) {
if (defValue == null) {
defValue = v;
} else {
defValue = defValue.withOverrides(v);
}
}
}
JsonFormat.Value v = _config.getDefaultPropertyFormat(_classInfo.getRawType());
if (v != null) {
if (defValue == null) {
defValue = v;
} else {
defValue = defValue.withOverrides(v);
}
}
return defValue;
}
/*
/**********************************************************
/* Introspection for serialization
/**********************************************************
*/
@Override
public Converter<Object,Object> findSerializationConverter()
{
if (_annotationIntrospector == null) {
return null;
}
return _createConverter(_annotationIntrospector.findSerializationConverter(_classInfo));
}
/**
* Method for determining whether null properties should be written
* out for a Bean of introspected type. This is based on global
* feature (lowest priority, passed as argument)
* and per-class annotation (highest priority).
*/
@Override
public JsonInclude.Value findPropertyInclusion(JsonInclude.Value defValue) {
if (_annotationIntrospector != null) {
Json
JacksonDatabind, 65
<FILEB>
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: (%s) %s",
re.getClass().getName(), re.getMessage());
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
if (isFactoryMethod(am) && am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
if (am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
} else {
return null;
}
return new StdKeyDeserializer(kind, raw);
}
@Override
public Object deserializeKey(String key, DeserializationContext ctxt)
throws IOException
{
if (key == null) { // is this even legal call?
return null;
}
try {
Object result = _parse(key, ctxt);
if (result != null) {
return result;
}
} catch (Exception re) {
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: %s", re.getMessage());
<CHANGEE>
}
if (_keyClass.isEnum() && ctxt.getConfig().isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
return null;
}
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation");
}
public Class<?> getKeyClass() { return _keyClass; }
protected Object _parse(String key, DeserializationContext ctxt) throws Exception
{
switch (_kind) {
case TYPE_BOOLEAN:
if ("true".equals(key)) {
<FILEE>
<FILEB>
*/
if (ac.getParameterCount() == 1) {
Class<?> actArg = ac.getRawParameterType(0);
for (Class<?> expArg : argTypes) {
if (expArg == actArg) {
return ac.getAnnotated();
}
}
}
}
return null;
}
@Override
public Method findFactoryMethod(Class<?>... expArgTypes)
{
// So, of all single-arg static methods:
for (AnnotatedMethod am : _classInfo.getStaticMethods()) {
// 24-Oct-2016, tatu: Better ensure it only takes 1 arg, no matter what
<CHANGES>
if (isFactoryMethod(am)) {
<CHANGEE>
// And must take one of expected arg types (or supertype)
Class<?> actualArgType = am.getRawParameterType(0);
for (Class<?> expArgType : expArgTypes) {
// And one that matches what we would pass in
if (actualArgType.isAssignableFrom(expArgType)) {
return am.getAnnotated();
}
}
}
}
return null;
}
{
/* First: return<SCANS>Properties.contains(name)) {
continue;
}
}
results.put(name, f);
}
}
return results;
}
/*
/**********************************************************
/* Helper methods, other
/**********************************************************
*/
@SuppressWarnings("unchecked")
public Converter<Object,Object> _createConverter(Object converterDef)
{
if (converterDef == null) {
return null;
}
if (converterDef instanceof Converter<?,?>) {
return (Converter<Object,Object>) converterDef;
}
if (!(converterDef instanceof Class)) {
throw new IllegalStateException("AnnotationIntrospector returned Converter definition of type "
+converterDef.getClass().getName()+"; expected type Converter or Class<Converter> instead");
}
Class<?> converterClass = (Class<?>)converterDef;
// there are some known "no class" markers to consider too:
if (converterClass == Converter.None.class || ClassUtil.isBogusClass(converterClass)) {
return null;
}
if (!Converter.class.isAssignableFrom(converterClass)) {
throw new IllegalStateException("AnnotationIntrospector returned Class "
+converterClass.getName()+"; expected Class<Converter>");
}
HandlerInstantiator hi = _config.getHandlerInstantiator();
Converter<?,?> conv = (hi == null) ? null : hi.converterInstance(_config, _classInfo, converterClass);
if (conv == null) {
conv = (Converter<?,?>) ClassUtil.createInstance(converterClass,
_config.canOverrideAccessModifiers());
}
return (Converter<Object,Object>) conv;
}
}
JacksonDatabind, 65
<FILEB>
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: (%s) %s",
re.getClass().getName(), re.getMessage());
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
if (isFactoryMethod(am) && am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
if (am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
} else {
return null;
}
return new StdKeyDeserializer(kind, raw);
}
@Override
public Object deserializeKey(String key, DeserializationContext ctxt)
throws IOException
{
if (key == null) { // is this even legal call?
return null;
}
try {
Object result = _parse(key, ctxt);
if (result != null) {
return result;
}
} catch (Exception re) {
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: %s", re.getMessage());
<CHANGEE>
}
if (_keyClass.isEnum() && ctxt.getConfig().isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
return null;
}
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation");
}
public Class<?> getKeyClass() { return _keyClass; }
protected Object _parse(String key, DeserializationContext ctxt) throws Exception
{
switch (_kind) {
case TYPE_BOOLEAN:
if ("true".equals(key)) {
<FILEE>
<FILEB>
*/
if (ac.getParameterCount() == 1) {
Class<?> actArg = ac.getRawParameterType(0);
for (Class<?> expArg : argTypes) {
if (expArg == actArg) {
return ac.getAnnotated();
}
}
}
}
return null;
}
@Override
public Method findFactoryMethod(Class<?>... expArgTypes)
{
// So, of all single-arg static methods:
for (AnnotatedMethod am : _classInfo.getStaticMethods()) {
// 24-Oct-2016, tatu: Better ensure it only takes 1 arg, no matter what
<CHANGES>
if (isFactoryMethod(am)) {
<CHANGEE>
// And must take one of expected arg types (or supertype)
Class<?> actualArgType = am.getRawParameterType(0);
for (Class<?> expArgType : expArgTypes) {
// And one that matches what we would pass in
if (actualArgType.isAssignableFrom(expArgType)) {
return am.getAnnotated();
}
}
}
}
return null;
}
{
/* First: return<SCANS> legit, so...
JsonMappingException e = ctxt.weirdStringException(text, _valueClass, msg);
if (cause != null) {
e.initCause(cause);
}
throw e;
// nothing to do here, yet? We'll fail anyway
}
JsonToken t = p.getCurrentToken();
// [databind#381]
if (t == JsonToken.START_ARRAY && ctxt.isEnabled(DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS)) {
p.nextToken();
final T value = deserialize(p, ctxt);
if (p.nextToken() != JsonToken.END_ARRAY) {
handleMissingEndArrayForSingle(p, ctxt);
}
return value;
}
if (t == JsonToken.VALUE_EMBEDDED_OBJECT) {
// Trivial cases; null to null, instance of type itself returned as is
Object ob = p.getEmbeddedObject();
if (ob == null) {
return null;
}
if (_valueClass.isAssignableFrom(ob.getClass())) {
return (T) ob;
}
return _deserializeEmbedded(ob, ctxt);
}
return (T) ctxt.handleUnexpectedToken(_valueClass, p);
}
protected abstract T _deserialize(String value, DeserializationContext ctxt) throws IOException;
protected T _deserializeEmbedded(Object ob, DeserializationContext ctxt) throws IOException {
// default impl: error out
ctxt.reportMappingException("Don't know how to convert embedded Object of type %s into %s",
ob.getClass().getName(), _valueClass.getName());
return null;
}
protected T _deserializeFromEmptyString() throws IOException {
return null;
}
/*
/**********************************************************
/* A general-purpose implementation
/**********************************************************
*/
/**
* "Chameleon" deserializer that works on simple types that are deserialized
* from a simple String.
*
* @since 2.4
*/
public static class Std extends FromStringDeserializer<Object>
{
private static final long serialVersionUID = 1;
public final static int STD_FILE = 1;
public final static int STD_URL = 2;
public final static int STD_URI = 3;
public final static int STD_CLASS = 4;
public final static
JacksonDatabind, 65
<FILEB>
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: (%s) %s",
re.getClass().getName(), re.getMessage());
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
if (isFactoryMethod(am) && am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
if (am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
} else {
return null;
}
return new StdKeyDeserializer(kind, raw);
}
@Override
public Object deserializeKey(String key, DeserializationContext ctxt)
throws IOException
{
if (key == null) { // is this even legal call?
return null;
}
try {
Object result = _parse(key, ctxt);
if (result != null) {
return result;
}
} catch (Exception re) {
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: %s", re.getMessage());
<CHANGEE>
}
if (_keyClass.isEnum() && ctxt.getConfig().isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
return null;
}
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation");
}
public Class<?> getKeyClass() { return _keyClass; }
protected Object _parse(String key, DeserializationContext ctxt) throws Exception
{
switch (_kind) {
case TYPE_BOOLEAN:
if ("true".equals(key)) {
<FILEE>
<FILEB>
*/
if (ac.getParameterCount() == 1) {
Class<?> actArg = ac.getRawParameterType(0);
for (Class<?> expArg : argTypes) {
if (expArg == actArg) {
return ac.getAnnotated();
}
}
}
}
return null;
}
@Override
public Method findFactoryMethod(Class<?>... expArgTypes)
{
// So, of all single-arg static methods:
for (AnnotatedMethod am : _classInfo.getStaticMethods()) {
// 24-Oct-2016, tatu: Better ensure it only takes 1 arg, no matter what
<CHANGES>
if (isFactoryMethod(am)) {
<CHANGEE>
// And must take one of expected arg types (or supertype)
Class<?> actualArgType = am.getRawParameterType(0);
for (Class<?> expArgType : expArgTypes) {
// And one that matches what we would pass in
if (actualArgType.isAssignableFrom(expArgType)) {
return am.getAnnotated();
}
}
}
}
return null;
}
{
/* First: return<SCANS>
* the same event as the one it pointed to upon call).
*<p>
* Note that this method is never called for JSON null literal,
* and thus deserializers need (and should) not check for it.
*
* @param p Parsed used for reading JSON content
* @param ctxt Context that can be used to access information about
* this deserialization activity.
*
* @return Deserialized value
*/
public abstract T deserialize(JsonParser p, DeserializationContext ctxt)
throws IOException, JsonProcessingException;
/**
* Alternate deserialization method (compared to the most commonly
* used, {@link #deserialize(JsonParser, DeserializationContext)}),
* which takes in initialized value instance, to be
* configured and/or populated by deserializer.
* Method is not necessarily used (or supported) by all types
* (it will not work for immutable types, for obvious reasons):
* most commonly it is used for Collections and Maps.
* It may be used both with "updating readers" (for POJOs) and
* when Collections and Maps use "getter as setter".
*<p>
* Default implementation just throws
* {@link UnsupportedOperationException}, to indicate that types
* that do not explicitly add support do not necessarily support
* update-existing-value operation (esp. immutable types)
*/
public T deserialize(JsonParser p, DeserializationContext ctxt, T intoValue)
throws IOException, JsonProcessingException
{
throw new UnsupportedOperationException("Can not update object of type "
+intoValue.getClass().getName()+" (by deserializer of type "+getClass().getName()+")");
}
/**
* Deserialization called when type being deserialized is defined to
* contain additional type identifier, to allow for correctly
* instantiating correct subtype. This can be due to annotation on
* type (or its supertype), or due to global settings without
* annotations.
*<p>
* Default implementation may work for some types, but ideally subclasses
* should not rely on current default implementation.
* Implementation is mostly provided to avoid compilation errors with older
* code.
*
* @param typeDeserializer Deserializer to use for handling type information
*/
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer)
throws IOException
{
// We could try
JacksonDatabind, 65
<FILEB>
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: (%s) %s",
re.getClass().getName(), re.getMessage());
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
if (isFactoryMethod(am) && am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
if (am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
} else {
return null;
}
return new StdKeyDeserializer(kind, raw);
}
@Override
public Object deserializeKey(String key, DeserializationContext ctxt)
throws IOException
{
if (key == null) { // is this even legal call?
return null;
}
try {
Object result = _parse(key, ctxt);
if (result != null) {
return result;
}
} catch (Exception re) {
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: %s", re.getMessage());
<CHANGEE>
}
if (_keyClass.isEnum() && ctxt.getConfig().isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
return null;
}
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation");
}
public Class<?> getKeyClass() { return _keyClass; }
protected Object _parse(String key, DeserializationContext ctxt) throws Exception
{
switch (_kind) {
case TYPE_BOOLEAN:
if ("true".equals(key)) {
<FILEE>
<FILEB>
*/
if (ac.getParameterCount() == 1) {
Class<?> actArg = ac.getRawParameterType(0);
for (Class<?> expArg : argTypes) {
if (expArg == actArg) {
return ac.getAnnotated();
}
}
}
}
return null;
}
@Override
public Method findFactoryMethod(Class<?>... expArgTypes)
{
// So, of all single-arg static methods:
for (AnnotatedMethod am : _classInfo.getStaticMethods()) {
// 24-Oct-2016, tatu: Better ensure it only takes 1 arg, no matter what
<CHANGES>
if (isFactoryMethod(am)) {
<CHANGEE>
// And must take one of expected arg types (or supertype)
Class<?> actualArgType = am.getRawParameterType(0);
for (Class<?> expArgType : expArgTypes) {
// And one that matches what we would pass in
if (actualArgType.isAssignableFrom(expArgType)) {
return am.getAnnotated();
}
}
}
}
return null;
}
{
/* First: return<SCANS> when deserializing from empty JSON Strings).
* Usually this is same as {@link #getNullValue} (which in turn
* is usually simply Java null), but it can be overridden
* for types. Or, if type should never be converted from empty
* String, method can also throw an exception.
*<p>
* Since version 2.6 (in which the context argument was added), call is
* expected to be made each and every time an empty value is needed.
*<p>
* Default implementation simple calls {@link #getNullValue} and
* returns value.
*
* @since 2.6 Added to replace earlier no-arguments variant
*/
public T getEmptyValue(DeserializationContext ctxt) throws JsonMappingException {
// Change the direction in 2.7
return getEmptyValue();
}
/**
* Accessor that can be used to check whether this deserializer
* is expecting to possibly get an Object Identifier value instead of full value
* serialization, and if so, should be able to resolve it to actual
* Object instance to return as deserialized value.
*<p>
* Default implementation returns null, as support can not be implemented
* generically. Some standard deserializers (most notably
* {@link com.fasterxml.jackson.databind.deser.BeanDeserializer})
* do implement this feature, and may return reader instance, depending on exact
* configuration of instance (which is based on type, and referring property).
*
* @return ObjectIdReader used for resolving possible Object Identifier
* value, instead of full value serialization, if deserializer can do that;
* null if no Object Id is expected.
*
* @since 2.0
*/
public ObjectIdReader getObjectIdReader() { return null; }
/**
* Method needed by {@link BeanDeserializerFactory} to properly link
* managed- and back-reference pairs.
*
* @since 2.2 (was moved out of <code>BeanDeserializerBase</code>)
*/
public SettableBeanProperty findBackReference(String refName)
{
throw new IllegalArgumentException("Can not handle managed/back reference '"+refName
+"': type: value deserializer of type "+getClass().getName()+" does not support them");
}
/*
/**********************************************************
/* Deprecated methods
/**********************************************************
*/
JacksonDatabind, 65
<FILEB>
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: (%s) %s",
re.getClass().getName(), re.getMessage());
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
if (isFactoryMethod(am) && am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
if (am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
} else {
return null;
}
return new StdKeyDeserializer(kind, raw);
}
@Override
public Object deserializeKey(String key, DeserializationContext ctxt)
throws IOException
{
if (key == null) { // is this even legal call?
return null;
}
try {
Object result = _parse(key, ctxt);
if (result != null) {
return result;
}
} catch (Exception re) {
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: %s", re.getMessage());
<CHANGEE>
}
if (_keyClass.isEnum() && ctxt.getConfig().isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
return null;
}
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation");
}
public Class<?> getKeyClass() { return _keyClass; }
protected Object _parse(String key, DeserializationContext ctxt) throws Exception
{
switch (_kind) {
case TYPE_BOOLEAN:
if ("true".equals(key)) {
<FILEE>
<FILEB>
*/
if (ac.getParameterCount() == 1) {
Class<?> actArg = ac.getRawParameterType(0);
for (Class<?> expArg : argTypes) {
if (expArg == actArg) {
return ac.getAnnotated();
}
}
}
}
return null;
}
@Override
public Method findFactoryMethod(Class<?>... expArgTypes)
{
// So, of all single-arg static methods:
for (AnnotatedMethod am : _classInfo.getStaticMethods()) {
// 24-Oct-2016, tatu: Better ensure it only takes 1 arg, no matter what
<CHANGES>
if (isFactoryMethod(am)) {
<CHANGEE>
// And must take one of expected arg types (or supertype)
Class<?> actualArgType = am.getRawParameterType(0);
for (Class<?> expArgType : expArgTypes) {
// And one that matches what we would pass in
if (actualArgType.isAssignableFrom(expArgType)) {
return am.getAnnotated();
}
}
}
}
return null;
}
{
/* First: return<SCANS>,T> converter,
JavaType delegateType, JsonDeserializer<?> delegateDeserializer)
{
super(delegateType);
_converter = converter;
_delegateType = delegateType;
_delegateDeserializer = (JsonDeserializer<Object>) delegateDeserializer;
}
/**
* @since 2.5
*/
protected StdDelegatingDeserializer(StdDelegatingDeserializer<T> src)
{
super(src);
_converter = src._converter;
_delegateType = src._delegateType;
_delegateDeserializer = src._delegateDeserializer;
}
/**
* Method used for creating resolved contextual instances. Must be
* overridden when sub-classing.
*/
protected StdDelegatingDeserializer<T> withDelegate(Converter<Object,T> converter,
JavaType delegateType, JsonDeserializer<?> delegateDeserializer)
{
if (getClass() != StdDelegatingDeserializer.class) {
throw new IllegalStateException("Sub-class "+getClass().getName()+" must override 'withDelegate'");
}
return new StdDelegatingDeserializer<T>(converter, delegateType, delegateDeserializer);
}
/*
/**********************************************************
/* Contextualization
/**********************************************************
*/
@Override
public void resolve(DeserializationContext ctxt)
throws JsonMappingException
{
if (_delegateDeserializer != null && _delegateDeserializer instanceof ResolvableDeserializer) {
((ResolvableDeserializer) _delegateDeserializer).resolve(ctxt);
}
}
@Override
public JsonDeserializer<?> createContextual(DeserializationContext ctxt, BeanProperty property)
throws JsonMappingException
{
// First: if already got serializer to delegate to, contextualize it:
if (_delegateDeserializer != null) {
JsonDeserializer<?> deser = ctxt.handleSecondaryContextualization(_delegateDeserializer,
property, _delegateType);
if (deser != _delegateDeserializer) {
return withDelegate(_converter, _delegateType, deser);
}
return this;
}
// Otherwise: figure out what is the fully generic delegate type, then find deserializer
JavaType delegateType = _converter.getInputType(ctxt.getTypeFactory());
return withDelegate(_converter, delegateType,
ctxt.findContextualValueDeserializer(delegateType, property));
}
/*
/**********************************************************
/* Accessors
/**********************************************************
*/
@Override
public JsonDeserializer<?> getDelegatee() {
return _delegateDeserializer;
}
JacksonDatabind, 65
<FILEB>
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: (%s) %s",
re.getClass().getName(), re.getMessage());
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
if (isFactoryMethod(am) && am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
if (am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
} else {
return null;
}
return new StdKeyDeserializer(kind, raw);
}
@Override
public Object deserializeKey(String key, DeserializationContext ctxt)
throws IOException
{
if (key == null) { // is this even legal call?
return null;
}
try {
Object result = _parse(key, ctxt);
if (result != null) {
return result;
}
} catch (Exception re) {
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: %s", re.getMessage());
<CHANGEE>
}
if (_keyClass.isEnum() && ctxt.getConfig().isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
return null;
}
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation");
}
public Class<?> getKeyClass() { return _keyClass; }
protected Object _parse(String key, DeserializationContext ctxt) throws Exception
{
switch (_kind) {
case TYPE_BOOLEAN:
if ("true".equals(key)) {
<FILEE>
<FILEB>
*/
if (ac.getParameterCount() == 1) {
Class<?> actArg = ac.getRawParameterType(0);
for (Class<?> expArg : argTypes) {
if (expArg == actArg) {
return ac.getAnnotated();
}
}
}
}
return null;
}
@Override
public Method findFactoryMethod(Class<?>... expArgTypes)
{
// So, of all single-arg static methods:
for (AnnotatedMethod am : _classInfo.getStaticMethods()) {
// 24-Oct-2016, tatu: Better ensure it only takes 1 arg, no matter what
<CHANGES>
if (isFactoryMethod(am)) {
<CHANGEE>
// And must take one of expected arg types (or supertype)
Class<?> actualArgType = am.getRawParameterType(0);
for (Class<?> expArgType : expArgTypes) {
// And one that matches what we would pass in
if (actualArgType.isAssignableFrom(expArgType)) {
return am.getAnnotated();
}
}
}
}
return null;
}
{
/* First: return<SCANS> @Override
public Class<?> handledType() {
return _delegateDeserializer.handledType();
}
/*
/**********************************************************
/* Serialization
/**********************************************************
*/
@Override
public T deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
Object delegateValue = _delegateDeserializer.deserialize(p, ctxt);
if (delegateValue == null) {
return null;
}
return convertValue(delegateValue);
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
/* 12-Apr-2016, tatu: As predicted, earlier handling does not work
* (see [databind#1189] for details). There does not seem to be any compelling
* way to combine polymorphic types, Converters, but the least sucky way
* is probably to use Converter and ignore polymorphic type. Alternative
* would be to try to change `TypeDeserializer` to accept `Converter` to
* invoke... but that is more intrusive, yet not guaranteeing success.
*/
// method called up to 2.7.3:
// Object delegateValue = _delegateDeserializer.deserializeWithType(p, ctxt, typeDeserializer);
// method called since 2.7.4
Object delegateValue = _delegateDeserializer.deserialize(p, ctxt);
if (delegateValue == null) {
return null;
}
return convertValue(delegateValue);
}
@SuppressWarnings("unchecked")
@Override
public T deserialize(JsonParser p, DeserializationContext ctxt, Object intoValue)
throws IOException
{
if (_delegateType.getRawClass().isAssignableFrom(intoValue.getClass())){
return (T) _delegateDeserializer.deserialize(p, ctxt, intoValue);
}
return (T) _handleIncompatibleUpdateValue(p, ctxt, intoValue);
}
/**
* Overridable handler method called when {@link #deserialize(JsonParser, DeserializationContext, Object)}
* has been called with a value that is not compatible with delegate value.
* Since no conversion are expected for such "updateValue" case, this is normally not
* an operation that can be permitted, and the default behavior is to throw exception.
* Sub-classes may choose to
JacksonDatabind, 65
<FILEB>
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: (%s) %s",
re.getClass().getName(), re.getMessage());
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
if (isFactoryMethod(am) && am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
if (am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
} else {
return null;
}
return new StdKeyDeserializer(kind, raw);
}
@Override
public Object deserializeKey(String key, DeserializationContext ctxt)
throws IOException
{
if (key == null) { // is this even legal call?
return null;
}
try {
Object result = _parse(key, ctxt);
if (result != null) {
return result;
}
} catch (Exception re) {
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: %s", re.getMessage());
<CHANGEE>
}
if (_keyClass.isEnum() && ctxt.getConfig().isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
return null;
}
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation");
}
public Class<?> getKeyClass() { return _keyClass; }
protected Object _parse(String key, DeserializationContext ctxt) throws Exception
{
switch (_kind) {
case TYPE_BOOLEAN:
if ("true".equals(key)) {
<FILEE>
<FILEB>
*/
if (ac.getParameterCount() == 1) {
Class<?> actArg = ac.getRawParameterType(0);
for (Class<?> expArg : argTypes) {
if (expArg == actArg) {
return ac.getAnnotated();
}
}
}
}
return null;
}
@Override
public Method findFactoryMethod(Class<?>... expArgTypes)
{
// So, of all single-arg static methods:
for (AnnotatedMethod am : _classInfo.getStaticMethods()) {
// 24-Oct-2016, tatu: Better ensure it only takes 1 arg, no matter what
<CHANGES>
if (isFactoryMethod(am)) {
<CHANGEE>
// And must take one of expected arg types (or supertype)
Class<?> actualArgType = am.getRawParameterType(0);
for (Class<?> expArgType : expArgTypes) {
// And one that matches what we would pass in
if (actualArgType.isAssignableFrom(expArgType)) {
return am.getAnnotated();
}
}
}
}
return null;
}
{
/* First: return<SCANS> try alternative approach if they have more information on
* exact usage and constraints.
*
* @since 2.6
*/
protected Object _handleIncompatibleUpdateValue(JsonParser p, DeserializationContext ctxt, Object intoValue)
throws IOException
{
throw new UnsupportedOperationException(String.format
("Can not update object of type %s (using deserializer for type %s)"
+intoValue.getClass().getName(), _delegateType));
}
/*
/**********************************************************
/* Overridable methods
/**********************************************************
*/
/**
* Method called to convert from "delegate value" (which was deserialized
* from JSON using standard Jackson deserializer for delegate type)
* into desired target type.
*<P>
* The default implementation uses configured {@link Converter} to do
* conversion.
*
* @param delegateValue
*
* @return Result of conversion
*/
protected T convertValue(Object delegateValue) {
return _converter.convert(delegateValue);
}
}
JacksonDatabind, 65
<FILEB>
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: (%s) %s",
re.getClass().getName(), re.getMessage());
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
if (isFactoryMethod(am) && am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
if (am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
} else {
return null;
}
return new StdKeyDeserializer(kind, raw);
}
@Override
public Object deserializeKey(String key, DeserializationContext ctxt)
throws IOException
{
if (key == null) { // is this even legal call?
return null;
}
try {
Object result = _parse(key, ctxt);
if (result != null) {
return result;
}
} catch (Exception re) {
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: %s", re.getMessage());
<CHANGEE>
}
if (_keyClass.isEnum() && ctxt.getConfig().isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
return null;
}
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation");
}
public Class<?> getKeyClass() { return _keyClass; }
protected Object _parse(String key, DeserializationContext ctxt) throws Exception
{
switch (_kind) {
case TYPE_BOOLEAN:
if ("true".equals(key)) {
<FILEE>
<FILEB>
*/
if (ac.getParameterCount() == 1) {
Class<?> actArg = ac.getRawParameterType(0);
for (Class<?> expArg : argTypes) {
if (expArg == actArg) {
return ac.getAnnotated();
}
}
}
}
return null;
}
@Override
public Method findFactoryMethod(Class<?>... expArgTypes)
{
// So, of all single-arg static methods:
for (AnnotatedMethod am : _classInfo.getStaticMethods()) {
// 24-Oct-2016, tatu: Better ensure it only takes 1 arg, no matter what
<CHANGES>
if (isFactoryMethod(am)) {
<CHANGEE>
// And must take one of expected arg types (or supertype)
Class<?> actualArgType = am.getRawParameterType(0);
for (Class<?> expArgType : expArgTypes) {
// And one that matches what we would pass in
if (actualArgType.isAssignableFrom(expArgType)) {
return am.getAnnotated();
}
}
}
}
return null;
}
{
/* First: return<SCANS> provider);
gen.writeEndArray();
}
@Override
public void serializeContents(Iterator<?> value, JsonGenerator gen,
SerializerProvider provider) throws IOException
{
if (value.hasNext()) {
final TypeSerializer typeSer = _valueTypeSerializer;
JsonSerializer<Object> prevSerializer = null;
Class<?> prevClass = null;
do {
Object elem = value.next();
if (elem == null) {
provider.defaultSerializeNull(gen);
continue;
}
JsonSerializer<Object> currSerializer = _elementSerializer;
if (currSerializer == null) {
// Minor optimization to avoid most lookups:
Class<?> cc = elem.getClass();
if (cc == prevClass) {
currSerializer = prevSerializer;
} else {
currSerializer = provider.findValueSerializer(cc, _property);
prevSerializer = currSerializer;
prevClass = cc;
}
}
if (typeSer == null) {
currSerializer.serialize(elem, gen, provider);
} else {
currSerializer.serializeWithType(elem, gen, provider, typeSer);
}
} while (value.hasNext());
}
}
}
JacksonDatabind, 65
<FILEB>
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: (%s) %s",
re.getClass().getName(), re.getMessage());
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
if (isFactoryMethod(am) && am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
if (am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
} else {
return null;
}
return new StdKeyDeserializer(kind, raw);
}
@Override
public Object deserializeKey(String key, DeserializationContext ctxt)
throws IOException
{
if (key == null) { // is this even legal call?
return null;
}
try {
Object result = _parse(key, ctxt);
if (result != null) {
return result;
}
} catch (Exception re) {
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: %s", re.getMessage());
<CHANGEE>
}
if (_keyClass.isEnum() && ctxt.getConfig().isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
return null;
}
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation");
}
public Class<?> getKeyClass() { return _keyClass; }
protected Object _parse(String key, DeserializationContext ctxt) throws Exception
{
switch (_kind) {
case TYPE_BOOLEAN:
if ("true".equals(key)) {
<FILEE>
<FILEB>
*/
if (ac.getParameterCount() == 1) {
Class<?> actArg = ac.getRawParameterType(0);
for (Class<?> expArg : argTypes) {
if (expArg == actArg) {
return ac.getAnnotated();
}
}
}
}
return null;
}
@Override
public Method findFactoryMethod(Class<?>... expArgTypes)
{
// So, of all single-arg static methods:
for (AnnotatedMethod am : _classInfo.getStaticMethods()) {
// 24-Oct-2016, tatu: Better ensure it only takes 1 arg, no matter what
<CHANGES>
if (isFactoryMethod(am)) {
<CHANGEE>
// And must take one of expected arg types (or supertype)
Class<?> actualArgType = am.getRawParameterType(0);
for (Class<?> expArgType : expArgTypes) {
// And one that matches what we would pass in
if (actualArgType.isAssignableFrom(expArgType)) {
return am.getAnnotated();
}
}
}
}
return null;
}
{
/* First: return<SCANS>package com.fasterxml.jackson.databind.exc;
import java.util.*;
import com.fasterxml.jackson.core.JsonLocation;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.JsonMappingException;
/**
* Specialized {@link JsonMappingException} sub-class specifically used
* to indicate problems due to encountering a JSON property that could
* not be mapped to an Object property (via getter, constructor argument
* or field).
*/
public class UnrecognizedPropertyException
extends PropertyBindingException
{
private static final long serialVersionUID = 1L;
public UnrecognizedPropertyException(JsonParser p, String msg, JsonLocation loc,
Class<?> referringClass, String propName,
Collection<Object> propertyIds)
{
super(p, msg, loc, referringClass, propName, propertyIds);
}
/**
* @deprecated Since 2.7
*/
@Deprecated // since 2.7
public UnrecognizedPropertyException(String msg, JsonLocation loc,
Class<?> referringClass, String propName,
Collection<Object> propertyIds)
{
super(msg, loc, referringClass, propName, propertyIds);
}
/**
* Factory method used for constructing instances of this exception type.
*
* @param p Underlying parser used for reading input being used for data-binding
* @param fromObjectOrClass Reference to either instance of problematic type (
* if available), or if not, type itself
* @param propertyName Name of unrecognized property
* @param propertyIds (optional, null if not available) Set of properties that
* type would recognize, if completely known: null if set can not be determined.
*/
public static UnrecognizedPropertyException from(JsonParser p,
Object fromObjectOrClass, String propertyName,
Collection<Object> propertyIds)
{
if (fromObjectOrClass == null) {
throw new IllegalArgumentException();
}
Class<?> ref;
if (fromObjectOrClass instanceof Class<?>) {
ref = (Class<?>) fromObjectOrClass;
} else {
ref = fromObjectOrClass.getClass();
}
String msg = "Unrecognized field \""+propertyName+"\" (class "+ref.getName()+"), not marked as ignorable";
UnrecognizedPropertyException e = new
JacksonDatabind, 65
<FILEB>
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: (%s) %s",
re.getClass().getName(), re.getMessage());
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
if (isFactoryMethod(am) && am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
if (am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
} else {
return null;
}
return new StdKeyDeserializer(kind, raw);
}
@Override
public Object deserializeKey(String key, DeserializationContext ctxt)
throws IOException
{
if (key == null) { // is this even legal call?
return null;
}
try {
Object result = _parse(key, ctxt);
if (result != null) {
return result;
}
} catch (Exception re) {
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: %s", re.getMessage());
<CHANGEE>
}
if (_keyClass.isEnum() && ctxt.getConfig().isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
return null;
}
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation");
}
public Class<?> getKeyClass() { return _keyClass; }
protected Object _parse(String key, DeserializationContext ctxt) throws Exception
{
switch (_kind) {
case TYPE_BOOLEAN:
if ("true".equals(key)) {
<FILEE>
<FILEB>
*/
if (ac.getParameterCount() == 1) {
Class<?> actArg = ac.getRawParameterType(0);
for (Class<?> expArg : argTypes) {
if (expArg == actArg) {
return ac.getAnnotated();
}
}
}
}
return null;
}
@Override
public Method findFactoryMethod(Class<?>... expArgTypes)
{
// So, of all single-arg static methods:
for (AnnotatedMethod am : _classInfo.getStaticMethods()) {
// 24-Oct-2016, tatu: Better ensure it only takes 1 arg, no matter what
<CHANGES>
if (isFactoryMethod(am)) {
<CHANGEE>
// And must take one of expected arg types (or supertype)
Class<?> actualArgType = am.getRawParameterType(0);
for (Class<?> expArgType : expArgTypes) {
// And one that matches what we would pass in
if (actualArgType.isAssignableFrom(expArgType)) {
return am.getAnnotated();
}
}
}
}
return null;
}
{
/* First: return<SCANS>Annotated ann, Object deserDef)
throws JsonMappingException
{
if (deserDef == null) {
return null;
}
JsonDeserializer<?> deser;
if (deserDef instanceof JsonDeserializer) {
deser = (JsonDeserializer<?>) deserDef;
} else {
/* Alas, there's no way to force return type of "either class
* X or Y" -- need to throw an exception after the fact
*/
if (!(deserDef instanceof Class)) {
throw new IllegalStateException("AnnotationIntrospector returned deserializer definition of type "+deserDef.getClass().getName()+"; expected type JsonDeserializer or Class<JsonDeserializer> instead");
}
Class<?> deserClass = (Class<?>)deserDef;
// there are some known "no class" markers to consider too:
if (deserClass == JsonDeserializer.None.class || ClassUtil.isBogusClass(deserClass)) {
return null;
}
if (!JsonDeserializer.class.isAssignableFrom(deserClass)) {
throw new IllegalStateException("AnnotationIntrospector returned Class "+deserClass.getName()+"; expected Class<JsonDeserializer>");
}
HandlerInstantiator hi = _config.getHandlerInstantiator();
deser = (hi == null) ? null : hi.deserializerInstance(_config, ann, deserClass);
if (deser == null) {
deser = (JsonDeserializer<?>) ClassUtil.createInstance(deserClass,
_config.canOverrideAccessModifiers());
}
}
// First: need to resolve
if (deser instanceof ResolvableDeserializer) {
((ResolvableDeserializer) deser).resolve(this);
}
return (JsonDeserializer<Object>) deser;
}
@Override
public final KeyDeserializer keyDeserializerInstance(Annotated ann, Object deserDef)
throws JsonMappingException
{
if (deserDef == null) {
return null;
}
KeyDeserializer deser;
if (deserDef instanceof KeyDeserializer) {
deser = (KeyDeserializer) deserDef;
} else {
if (!(deserDef instanceof Class)) {
throw new IllegalStateException("AnnotationIntrospector returned key deserializer definition of type "
+deserDef.getClass().getName()
+"; expected type KeyDeserializer or Class<KeyDeserializer> instead");
}
Class<?> deserClass = (Class<?>)de
JacksonDatabind, 65
<FILEB>
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: (%s) %s",
re.getClass().getName(), re.getMessage());
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
if (isFactoryMethod(am) && am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
if (am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
} else {
return null;
}
return new StdKeyDeserializer(kind, raw);
}
@Override
public Object deserializeKey(String key, DeserializationContext ctxt)
throws IOException
{
if (key == null) { // is this even legal call?
return null;
}
try {
Object result = _parse(key, ctxt);
if (result != null) {
return result;
}
} catch (Exception re) {
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: %s", re.getMessage());
<CHANGEE>
}
if (_keyClass.isEnum() && ctxt.getConfig().isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
return null;
}
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation");
}
public Class<?> getKeyClass() { return _keyClass; }
protected Object _parse(String key, DeserializationContext ctxt) throws Exception
{
switch (_kind) {
case TYPE_BOOLEAN:
if ("true".equals(key)) {
<FILEE>
<FILEB>
*/
if (ac.getParameterCount() == 1) {
Class<?> actArg = ac.getRawParameterType(0);
for (Class<?> expArg : argTypes) {
if (expArg == actArg) {
return ac.getAnnotated();
}
}
}
}
return null;
}
@Override
public Method findFactoryMethod(Class<?>... expArgTypes)
{
// So, of all single-arg static methods:
for (AnnotatedMethod am : _classInfo.getStaticMethods()) {
// 24-Oct-2016, tatu: Better ensure it only takes 1 arg, no matter what
<CHANGES>
if (isFactoryMethod(am)) {
<CHANGEE>
// And must take one of expected arg types (or supertype)
Class<?> actualArgType = am.getRawParameterType(0);
for (Class<?> expArgType : expArgTypes) {
// And one that matches what we would pass in
if (actualArgType.isAssignableFrom(expArgType)) {
return am.getAnnotated();
}
}
}
}
return null;
}
{
/* First: return<SCANS>serDef;
// there are some known "no class" markers to consider too:
if (deserClass == KeyDeserializer.None.class || ClassUtil.isBogusClass(deserClass)) {
return null;
}
if (!KeyDeserializer.class.isAssignableFrom(deserClass)) {
throw new IllegalStateException("AnnotationIntrospector returned Class "+deserClass.getName()
+"; expected Class<KeyDeserializer>");
}
HandlerInstantiator hi = _config.getHandlerInstantiator();
deser = (hi == null) ? null : hi.keyDeserializerInstance(_config, ann, deserClass);
if (deser == null) {
deser = (KeyDeserializer) ClassUtil.createInstance(deserClass,
_config.canOverrideAccessModifiers());
}
}
// First: need to resolve
if (deser instanceof ResolvableDeserializer) {
((ResolvableDeserializer) deser).resolve(this);
}
return deser;
}
/*
/**********************************************************
/* Extended API
/**********************************************************
*/
/**
* Fluent factory method used for constructing a blueprint instance
* with different factory
*/
public abstract DefaultDeserializationContext with(DeserializerFactory factory);
/**
* Method called to create actual usable per-deserialization
* context instance.
*/
public abstract DefaultDeserializationContext createInstance(
DeserializationConfig config, JsonParser jp, InjectableValues values);
/*
/**********************************************************
/* And then the concrete implementation class
/**********************************************************
*/
/**
* Actual full concrete implementation
*/
public final static class Impl extends DefaultDeserializationContext
{
private static final long serialVersionUID = 1L;
/**
* Default constructor for a blueprint object, which will use the standard
* {@link DeserializerCache}, given factory.
*/
public Impl(DeserializerFactory df) {
super(df, null);
}
protected Impl(Impl src,
DeserializationConfig config, JsonParser jp, InjectableValues values) {
super(src, config, jp, values);
}
protected Impl(Impl src) { super(src); }
protected Impl(Impl src, DeserializerFactory factory) {
super(src, factory);
}
@Override
public DefaultDeserializationContext copy() {
if (getClass() != Impl.class) {
return super.copy();
}
JacksonDatabind, 65
<FILEB>
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: (%s) %s",
re.getClass().getName(), re.getMessage());
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
if (isFactoryMethod(am) && am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
if (am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
} else {
return null;
}
return new StdKeyDeserializer(kind, raw);
}
@Override
public Object deserializeKey(String key, DeserializationContext ctxt)
throws IOException
{
if (key == null) { // is this even legal call?
return null;
}
try {
Object result = _parse(key, ctxt);
if (result != null) {
return result;
}
} catch (Exception re) {
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: %s", re.getMessage());
<CHANGEE>
}
if (_keyClass.isEnum() && ctxt.getConfig().isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
return null;
}
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation");
}
public Class<?> getKeyClass() { return _keyClass; }
protected Object _parse(String key, DeserializationContext ctxt) throws Exception
{
switch (_kind) {
case TYPE_BOOLEAN:
if ("true".equals(key)) {
<FILEE>
<FILEB>
*/
if (ac.getParameterCount() == 1) {
Class<?> actArg = ac.getRawParameterType(0);
for (Class<?> expArg : argTypes) {
if (expArg == actArg) {
return ac.getAnnotated();
}
}
}
}
return null;
}
@Override
public Method findFactoryMethod(Class<?>... expArgTypes)
{
// So, of all single-arg static methods:
for (AnnotatedMethod am : _classInfo.getStaticMethods()) {
// 24-Oct-2016, tatu: Better ensure it only takes 1 arg, no matter what
<CHANGES>
if (isFactoryMethod(am)) {
<CHANGEE>
// And must take one of expected arg types (or supertype)
Class<?> actualArgType = am.getRawParameterType(0);
for (Class<?> expArgType : expArgTypes) {
// And one that matches what we would pass in
if (actualArgType.isAssignableFrom(expArgType)) {
return am.getAnnotated();
}
}
}
}
return null;
}
{
/* First: return<SCANS> static ReferenceType upgradeFrom(JavaType baseType, JavaType refdType) {
if (refdType == null) {
throw new IllegalArgumentException("Missing referencedType");
}
// 19-Oct-2015, tatu: Not sure if and how other types could be used as base;
// will cross that bridge if and when need be
if (baseType instanceof TypeBase) {
return new ReferenceType((TypeBase) baseType, refdType);
}
throw new IllegalArgumentException("Can not upgrade from an instance of "+baseType.getClass());
}
/**
* @since 2.7
*/
public static ReferenceType construct(Class<?> cls, TypeBindings bindings,
JavaType superClass, JavaType[] superInts, JavaType refType)
{
return new ReferenceType(cls, bindings, superClass, superInts,
refType, null, null, null, false);
}
@Deprecated // since 2.7
public static ReferenceType construct(Class<?> cls, JavaType refType) {
return new ReferenceType(cls, TypeBindings.emptyBindings(),
// !!! TODO: missing supertypes
null, null, null, refType, null, null, false);
}
@Override
public JavaType withContentType(JavaType contentType) {
if (_referencedType == contentType) {
return this;
}
return new ReferenceType(_class, _bindings, _superClass, _superInterfaces,
contentType, _anchorType, _valueHandler, _typeHandler, _asStatic);
}
@Override
public ReferenceType withTypeHandler(Object h)
{
if (h == _typeHandler) {
return this;
}
return new ReferenceType(_class, _bindings, _superClass, _superInterfaces,
_referencedType, _anchorType, _valueHandler, h, _asStatic);
}
@Override
public ReferenceType withContentTypeHandler(Object h)
{
if (h == _referencedType.<Object>getTypeHandler()) {
return this;
}
return new ReferenceType(_class, _bindings, _superClass, _superInterfaces,
_referencedType.withTypeHandler(h), _anchorType,
_valueHandler, _typeHandler, _asStatic);
}
@Override
public ReferenceType withValueHandler(Object
JacksonDatabind, 65
<FILEB>
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: (%s) %s",
re.getClass().getName(), re.getMessage());
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
if (isFactoryMethod(am) && am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
if (am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
} else {
return null;
}
return new StdKeyDeserializer(kind, raw);
}
@Override
public Object deserializeKey(String key, DeserializationContext ctxt)
throws IOException
{
if (key == null) { // is this even legal call?
return null;
}
try {
Object result = _parse(key, ctxt);
if (result != null) {
return result;
}
} catch (Exception re) {
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: %s", re.getMessage());
<CHANGEE>
}
if (_keyClass.isEnum() && ctxt.getConfig().isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
return null;
}
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation");
}
public Class<?> getKeyClass() { return _keyClass; }
protected Object _parse(String key, DeserializationContext ctxt) throws Exception
{
switch (_kind) {
case TYPE_BOOLEAN:
if ("true".equals(key)) {
<FILEE>
<FILEB>
*/
if (ac.getParameterCount() == 1) {
Class<?> actArg = ac.getRawParameterType(0);
for (Class<?> expArg : argTypes) {
if (expArg == actArg) {
return ac.getAnnotated();
}
}
}
}
return null;
}
@Override
public Method findFactoryMethod(Class<?>... expArgTypes)
{
// So, of all single-arg static methods:
for (AnnotatedMethod am : _classInfo.getStaticMethods()) {
// 24-Oct-2016, tatu: Better ensure it only takes 1 arg, no matter what
<CHANGES>
if (isFactoryMethod(am)) {
<CHANGEE>
// And must take one of expected arg types (or supertype)
Class<?> actualArgType = am.getRawParameterType(0);
for (Class<?> expArgType : expArgTypes) {
// And one that matches what we would pass in
if (actualArgType.isAssignableFrom(expArgType)) {
return am.getAnnotated();
}
}
}
}
return null;
}
{
/* First: return<SCANS> @Override
public boolean hasContentType() {
return true;
}
@Override
public boolean isReferenceType() {
return true;
}
@Override
public StringBuilder getErasedSignature(StringBuilder sb) {
return _classSignature(_class, sb, true);
}
@Override
public StringBuilder getGenericSignature(StringBuilder sb)
{
_classSignature(_class, sb, false);
sb.append('<');
sb = _referencedType.getGenericSignature(sb);
sb.append(">;");
return sb;
}
/*
/**********************************************************
/* Extended API
/**********************************************************
*/
public JavaType getAnchorType() {
return _anchorType;
}
/**
* Convenience accessor that allows checking whether this is the anchor type
* itself; if not, it must be one of supertypes that is also a {@link ReferenceType}
*/
public boolean isAnchorType() {
return (_anchorType == this);
}
/*
/**********************************************************
/* Standard methods
/**********************************************************
*/
@Override
public String toString()
{
return new StringBuilder(40)
.append("[reference type, class ")
.append(buildCanonicalName())
.append('<')
.append(_referencedType)
.append('>')
.append(']')
.toString();
}
@Override
public boolean equals(Object o)
{
if (o == this) return true;
if (o == null) return false;
if (o.getClass() != getClass()) return false;
ReferenceType other = (ReferenceType) o;
if (other._class != _class) return false;
// Otherwise actually mostly worry about referenced type
return _referencedType.equals(other._referencedType);
}
}
JacksonDatabind, 65
<FILEB>
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: (%s) %s",
re.getClass().getName(), re.getMessage());
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
if (isFactoryMethod(am) && am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
if (am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
} else {
return null;
}
return new StdKeyDeserializer(kind, raw);
}
@Override
public Object deserializeKey(String key, DeserializationContext ctxt)
throws IOException
{
if (key == null) { // is this even legal call?
return null;
}
try {
Object result = _parse(key, ctxt);
if (result != null) {
return result;
}
} catch (Exception re) {
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: %s", re.getMessage());
<CHANGEE>
}
if (_keyClass.isEnum() && ctxt.getConfig().isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
return null;
}
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation");
}
public Class<?> getKeyClass() { return _keyClass; }
protected Object _parse(String key, DeserializationContext ctxt) throws Exception
{
switch (_kind) {
case TYPE_BOOLEAN:
if ("true".equals(key)) {
<FILEE>
<FILEB>
*/
if (ac.getParameterCount() == 1) {
Class<?> actArg = ac.getRawParameterType(0);
for (Class<?> expArg : argTypes) {
if (expArg == actArg) {
return ac.getAnnotated();
}
}
}
}
return null;
}
@Override
public Method findFactoryMethod(Class<?>... expArgTypes)
{
// So, of all single-arg static methods:
for (AnnotatedMethod am : _classInfo.getStaticMethods()) {
// 24-Oct-2016, tatu: Better ensure it only takes 1 arg, no matter what
<CHANGES>
if (isFactoryMethod(am)) {
<CHANGEE>
// And must take one of expected arg types (or supertype)
Class<?> actualArgType = am.getRawParameterType(0);
for (Class<?> expArgType : expArgTypes) {
// And one that matches what we would pass in
if (actualArgType.isAssignableFrom(expArgType)) {
return am.getAnnotated();
}
}
}
}
return null;
}
{
/* First: return<SCANS>unlikely...)
return provider.isEnabled(MapperFeature.USE_STATIC_TYPING);
}
/*
/**********************************************************
/* Accessors
/**********************************************************
*/
@Override
public boolean isEmpty(SerializerProvider provider, T value)
{
if ((value == null) || _isValueEmpty(value)) {
return true;
}
if (_contentInclusion == null) {
return false;
}
Object contents = _getReferenced(value);
JsonSerializer<Object> ser = _valueSerializer;
if (ser == null) {
try {
ser = _findCachedSerializer(provider, contents.getClass());
} catch (JsonMappingException e) { // nasty but necessary
throw new RuntimeJsonMappingException(e);
}
}
return ser.isEmpty(provider, contents);
}
@Override
public boolean isUnwrappingSerializer() {
return (_unwrapper != null);
}
/*
/**********************************************************
/* Serialization methods
/**********************************************************
*/
@Override
public void serialize(T ref, JsonGenerator g, SerializerProvider provider)
throws IOException
{
Object value = _getReferencedIfPresent(ref);
if (value == null) {
if (_unwrapper == null) {
provider.defaultSerializeNull(g);
}
return;
}
JsonSerializer<Object> ser = _valueSerializer;
if (ser == null) {
ser = _findCachedSerializer(provider, value.getClass());
}
if (_valueTypeSerializer != null) {
ser.serializeWithType(value, g, provider, _valueTypeSerializer);
} else {
ser.serialize(value, g, provider);
}
}
@Override
public void serializeWithType(T ref,
JsonGenerator g, SerializerProvider provider,
TypeSerializer typeSer) throws IOException
{
Object value = _getReferencedIfPresent(ref);
if (value == null) {
if (_unwrapper == null) {
provider.defaultSerializeNull(g);
}
return;
}
// 19-Apr-2016, tatu: In order to basically "skip" the whole wrapper level
// (which is what non-polymorphic serialization does too), we will need
// to simply delegate call, I think, and NOT try to use it here.
// Otherwise apply type
JacksonDatabind, 65
<FILEB>
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: (%s) %s",
re.getClass().getName(), re.getMessage());
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
if (isFactoryMethod(am) && am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
if (am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
} else {
return null;
}
return new StdKeyDeserializer(kind, raw);
}
@Override
public Object deserializeKey(String key, DeserializationContext ctxt)
throws IOException
{
if (key == null) { // is this even legal call?
return null;
}
try {
Object result = _parse(key, ctxt);
if (result != null) {
return result;
}
} catch (Exception re) {
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: %s", re.getMessage());
<CHANGEE>
}
if (_keyClass.isEnum() && ctxt.getConfig().isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
return null;
}
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation");
}
public Class<?> getKeyClass() { return _keyClass; }
protected Object _parse(String key, DeserializationContext ctxt) throws Exception
{
switch (_kind) {
case TYPE_BOOLEAN:
if ("true".equals(key)) {
<FILEE>
<FILEB>
*/
if (ac.getParameterCount() == 1) {
Class<?> actArg = ac.getRawParameterType(0);
for (Class<?> expArg : argTypes) {
if (expArg == actArg) {
return ac.getAnnotated();
}
}
}
}
return null;
}
@Override
public Method findFactoryMethod(Class<?>... expArgTypes)
{
// So, of all single-arg static methods:
for (AnnotatedMethod am : _classInfo.getStaticMethods()) {
// 24-Oct-2016, tatu: Better ensure it only takes 1 arg, no matter what
<CHANGES>
if (isFactoryMethod(am)) {
<CHANGEE>
// And must take one of expected arg types (or supertype)
Class<?> actualArgType = am.getRawParameterType(0);
for (Class<?> expArgType : expArgTypes) {
// And one that matches what we would pass in
if (actualArgType.isAssignableFrom(expArgType)) {
return am.getAnnotated();
}
}
}
}
return null;
}
{
/* First: return<SCANS>-prefix/suffix, then std serialize:
/*
typeSer.writeTypePrefixForScalar(ref, g);
serialize(ref, g, provider);
typeSer.writeTypeSuffixForScalar(ref, g);
*/
JsonSerializer<Object> ser = _valueSerializer;
if (ser == null) {
ser = _findCachedSerializer(provider, value.getClass());
}
ser.serializeWithType(value, g, provider, typeSer);
}
/*
/**********************************************************
/* Introspection support
/**********************************************************
*/
@Override
public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType typeHint)
throws JsonMappingException
{
JsonSerializer<?> ser = _valueSerializer;
if (ser == null) {
ser = _findSerializer(visitor.getProvider(), _referredType, _property);
if (_unwrapper != null) {
ser = ser.unwrappingSerializer(_unwrapper);
}
}
ser.acceptJsonFormatVisitor(visitor, _referredType);
}
/*
/**********************************************************
/* Helper methods
/**********************************************************
*/
/**
* Helper method that encapsulates logic of retrieving and caching required
* serializer.
*/
private final JsonSerializer<Object> _findCachedSerializer(SerializerProvider provider,
Class<?> type) throws JsonMappingException
{
JsonSerializer<Object> ser = _dynamicSerializers.serializerFor(type);
if (ser == null) {
ser = _findSerializer(provider, type, _property);
if (_unwrapper != null) {
ser = ser.unwrappingSerializer(_unwrapper);
}
_dynamicSerializers = _dynamicSerializers.newWith(type, ser);
}
return ser;
}
private final JsonSerializer<Object> _findSerializer(SerializerProvider provider,
Class<?> type, BeanProperty prop) throws JsonMappingException
{
return provider.findTypedValueSerializer(type, true, prop);
}
private final JsonSerializer<Object> _findSerializer(SerializerProvider provider,
JavaType type, BeanProperty prop) throws JsonMappingException
{
return provider.findTypedValueSerializer(type, true, prop);
}
}
JacksonDatabind, 65
<FILEB>
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: (%s) %s",
re.getClass().getName(), re.getMessage());
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
if (isFactoryMethod(am) && am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
if (am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
} else {
return null;
}
return new StdKeyDeserializer(kind, raw);
}
@Override
public Object deserializeKey(String key, DeserializationContext ctxt)
throws IOException
{
if (key == null) { // is this even legal call?
return null;
}
try {
Object result = _parse(key, ctxt);
if (result != null) {
return result;
}
} catch (Exception re) {
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: %s", re.getMessage());
<CHANGEE>
}
if (_keyClass.isEnum() && ctxt.getConfig().isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
return null;
}
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation");
}
public Class<?> getKeyClass() { return _keyClass; }
protected Object _parse(String key, DeserializationContext ctxt) throws Exception
{
switch (_kind) {
case TYPE_BOOLEAN:
if ("true".equals(key)) {
<FILEE>
<FILEB>
*/
if (ac.getParameterCount() == 1) {
Class<?> actArg = ac.getRawParameterType(0);
for (Class<?> expArg : argTypes) {
if (expArg == actArg) {
return ac.getAnnotated();
}
}
}
}
return null;
}
@Override
public Method findFactoryMethod(Class<?>... expArgTypes)
{
// So, of all single-arg static methods:
for (AnnotatedMethod am : _classInfo.getStaticMethods()) {
// 24-Oct-2016, tatu: Better ensure it only takes 1 arg, no matter what
<CHANGES>
if (isFactoryMethod(am)) {
<CHANGEE>
// And must take one of expected arg types (or supertype)
Class<?> actualArgType = am.getRawParameterType(0);
for (Class<?> expArgType : expArgTypes) {
// And one that matches what we would pass in
if (actualArgType.isAssignableFrom(expArgType)) {
return am.getAnnotated();
}
}
}
}
return null;
}
{
/* First: return<SCANS> probably not even then).
*/
public final Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
JsonToken t = p.getCurrentToken();
if (t == JsonToken.VALUE_NULL) {
return _valueDeserializer.getNullValue(ctxt);
}
if (_valueTypeDeserializer != null) {
return _valueDeserializer.deserializeWithType(p, ctxt, _valueTypeDeserializer);
}
return _valueDeserializer.deserialize(p, ctxt);
}
/*
/**********************************************************
/* Helper methods
/**********************************************************
*/
/**
* Method that takes in exception of any type, and casts or wraps it
* to an IOException or its subclass.
*/
protected void _throwAsIOE(JsonParser p, Exception e, Object value) throws IOException
{
if (e instanceof IllegalArgumentException) {
String actType = (value == null) ? "[NULL]" : value.getClass().getName();
StringBuilder msg = new StringBuilder("Problem deserializing property '").append(getName());
msg.append("' (expected type: ").append(getType());
msg.append("; actual type: ").append(actType).append(")");
String origMsg = e.getMessage();
if (origMsg != null) {
msg.append(", problem: ").append(origMsg);
} else {
msg.append(" (no error message provided)");
}
throw JsonMappingException.from(p, msg.toString(), e);
}
_throwAsIOE(p, e);
}
/**
* @since 2.7
*/
protected IOException _throwAsIOE(JsonParser p, Exception e) throws IOException
{
if (e instanceof IOException) {
throw (IOException) e;
}
if (e instanceof RuntimeException) {
throw (RuntimeException) e;
}
// let's wrap the innermost problem
Throwable th = e;
while (th.getCause() != null) {
th = th.getCause();
}
throw JsonMappingException.from(p, th.getMessage(), th);
}
@Deprecated // since 2.7
protected IOException _throwAsIOE(Exception e) throws IOException {
return _throwAsIOE((JsonParser) null, e);
}
// 10-Oct-2015, tatu: _Should
JacksonDatabind, 65
<FILEB>
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: (%s) %s",
re.getClass().getName(), re.getMessage());
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
if (isFactoryMethod(am) && am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
if (am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
} else {
return null;
}
return new StdKeyDeserializer(kind, raw);
}
@Override
public Object deserializeKey(String key, DeserializationContext ctxt)
throws IOException
{
if (key == null) { // is this even legal call?
return null;
}
try {
Object result = _parse(key, ctxt);
if (result != null) {
return result;
}
} catch (Exception re) {
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: %s", re.getMessage());
<CHANGEE>
}
if (_keyClass.isEnum() && ctxt.getConfig().isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
return null;
}
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation");
}
public Class<?> getKeyClass() { return _keyClass; }
protected Object _parse(String key, DeserializationContext ctxt) throws Exception
{
switch (_kind) {
case TYPE_BOOLEAN:
if ("true".equals(key)) {
<FILEE>
<FILEB>
*/
if (ac.getParameterCount() == 1) {
Class<?> actArg = ac.getRawParameterType(0);
for (Class<?> expArg : argTypes) {
if (expArg == actArg) {
return ac.getAnnotated();
}
}
}
}
return null;
}
@Override
public Method findFactoryMethod(Class<?>... expArgTypes)
{
// So, of all single-arg static methods:
for (AnnotatedMethod am : _classInfo.getStaticMethods()) {
// 24-Oct-2016, tatu: Better ensure it only takes 1 arg, no matter what
<CHANGES>
if (isFactoryMethod(am)) {
<CHANGEE>
// And must take one of expected arg types (or supertype)
Class<?> actualArgType = am.getRawParameterType(0);
for (Class<?> expArgType : expArgTypes) {
// And one that matches what we would pass in
if (actualArgType.isAssignableFrom(expArgType)) {
return am.getAnnotated();
}
}
}
}
return null;
}
{
/* First: return<SCANS> name = type.getName();
// Hibernate uses proxies heavily as well:
if (name.startsWith("net.sf.cglib.proxy.")
|| name.startsWith("org.hibernate.proxy.")) {
return true;
}
// Not one of known proxies, nope:
return false;
}
/**
* Helper method that checks if given class is a concrete one;
* that is, not an interface or abstract class.
*/
public static boolean isConcrete(Class<?> type)
{
int mod = type.getModifiers();
return (mod & (Modifier.INTERFACE | Modifier.ABSTRACT)) == 0;
}
public static boolean isConcrete(Member member)
{
int mod = member.getModifiers();
return (mod & (Modifier.INTERFACE | Modifier.ABSTRACT)) == 0;
}
public static boolean isCollectionMapOrArray(Class<?> type)
{
if (type.isArray()) return true;
if (Collection.class.isAssignableFrom(type)) return true;
if (Map.class.isAssignableFrom(type)) return true;
return false;
}
/*
/**********************************************************
/* Type name handling methods
/**********************************************************
*/
/**
* Helper method used to construct appropriate description
* when passed either type (Class) or an instance; in latter
* case, class of instance is to be used.
*/
public static String getClassDescription(Object classOrInstance)
{
if (classOrInstance == null) {
return "unknown";
}
Class<?> cls = (classOrInstance instanceof Class<?>) ?
(Class<?>) classOrInstance : classOrInstance.getClass();
return cls.getName();
}
/*
/**********************************************************
/* Class loading
/**********************************************************
*/
/**
* @deprecated Since 2.6, use method in {@link com.fasterxml.jackson.databind.type.TypeFactory}.
*/
@Deprecated
public static Class<?> findClass(String className) throws ClassNotFoundException
{
// [JACKSON-597]: support primitive types (and void)
if (className.indexOf('.') < 0) {
if ("int".equals(className)) return Integer.TYPE;
if ("long".equals(className)) return Long.TYPE;
if ("float".equals(className)) return Float.TYPE
JacksonDatabind, 65
<FILEB>
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: (%s) %s",
re.getClass().getName(), re.getMessage());
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
if (isFactoryMethod(am) && am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
if (am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
} else {
return null;
}
return new StdKeyDeserializer(kind, raw);
}
@Override
public Object deserializeKey(String key, DeserializationContext ctxt)
throws IOException
{
if (key == null) { // is this even legal call?
return null;
}
try {
Object result = _parse(key, ctxt);
if (result != null) {
return result;
}
} catch (Exception re) {
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: %s", re.getMessage());
<CHANGEE>
}
if (_keyClass.isEnum() && ctxt.getConfig().isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
return null;
}
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation");
}
public Class<?> getKeyClass() { return _keyClass; }
protected Object _parse(String key, DeserializationContext ctxt) throws Exception
{
switch (_kind) {
case TYPE_BOOLEAN:
if ("true".equals(key)) {
<FILEE>
<FILEB>
*/
if (ac.getParameterCount() == 1) {
Class<?> actArg = ac.getRawParameterType(0);
for (Class<?> expArg : argTypes) {
if (expArg == actArg) {
return ac.getAnnotated();
}
}
}
}
return null;
}
@Override
public Method findFactoryMethod(Class<?>... expArgTypes)
{
// So, of all single-arg static methods:
for (AnnotatedMethod am : _classInfo.getStaticMethods()) {
// 24-Oct-2016, tatu: Better ensure it only takes 1 arg, no matter what
<CHANGES>
if (isFactoryMethod(am)) {
<CHANGEE>
// And must take one of expected arg types (or supertype)
Class<?> actualArgType = am.getRawParameterType(0);
for (Class<?> expArgType : expArgTypes) {
// And one that matches what we would pass in
if (actualArgType.isAssignableFrom(expArgType)) {
return am.getAnnotated();
}
}
}
}
return null;
}
{
/* First: return<SCANS>SON-101]: this can fail on platforms like
// Google App Engine); so let's only fail if we really needed it...
if (!ao.isAccessible()) {
Class<?> declClass = member.getDeclaringClass();
throw new IllegalArgumentException("Can not access "+member+" (from class "+declClass.getName()+"; failed to set access: "+se.getMessage());
}
}
}
/*
/**********************************************************
/* Enum type detection
/**********************************************************
*/
/**
* Helper method that can be used to dynamically figure out
* enumeration type of given {@link EnumSet}, without having
* access to its declaration.
* Code is needed to work around design flaw in JDK.
*/
public static Class<? extends Enum<?>> findEnumType(EnumSet<?> s)
{
// First things first: if not empty, easy to determine
if (!s.isEmpty()) {
return findEnumType(s.iterator().next());
}
// Otherwise need to locate using an internal field
return EnumTypeLocator.instance.enumTypeFor(s);
}
/**
* Helper method that can be used to dynamically figure out
* enumeration type of given {@link EnumSet}, without having
* access to its declaration.
* Code is needed to work around design flaw in JDK.
*/
public static Class<? extends Enum<?>> findEnumType(EnumMap<?,?> m)
{
if (!m.isEmpty()) {
return findEnumType(m.keySet().iterator().next());
}
// Otherwise need to locate using an internal field
return EnumTypeLocator.instance.enumTypeFor(m);
}
/**
* Helper method that can be used to dynamically figure out formal
* enumeration type (class) for given enumeration. This is either
* class of enum instance (for "simple" enumerations), or its
* superclass (for enums with instance fields or methods)
*/
@SuppressWarnings("unchecked")
public static Class<? extends Enum<?>> findEnumType(Enum<?> en)
{
// enums with "body" are sub-classes of the formal type
Class<?> ec = en.getClass();
if (ec.getSuperclass() != Enum.class) {
ec = ec.getSuperclass();
}
return (Class<? extends Enum<?>>) ec;
}
/**
JacksonDatabind, 65
<FILEB>
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: (%s) %s",
re.getClass().getName(), re.getMessage());
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
if (isFactoryMethod(am) && am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
if (am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
} else {
return null;
}
return new StdKeyDeserializer(kind, raw);
}
@Override
public Object deserializeKey(String key, DeserializationContext ctxt)
throws IOException
{
if (key == null) { // is this even legal call?
return null;
}
try {
Object result = _parse(key, ctxt);
if (result != null) {
return result;
}
} catch (Exception re) {
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: %s", re.getMessage());
<CHANGEE>
}
if (_keyClass.isEnum() && ctxt.getConfig().isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
return null;
}
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation");
}
public Class<?> getKeyClass() { return _keyClass; }
protected Object _parse(String key, DeserializationContext ctxt) throws Exception
{
switch (_kind) {
case TYPE_BOOLEAN:
if ("true".equals(key)) {
<FILEE>
<FILEB>
*/
if (ac.getParameterCount() == 1) {
Class<?> actArg = ac.getRawParameterType(0);
for (Class<?> expArg : argTypes) {
if (expArg == actArg) {
return ac.getAnnotated();
}
}
}
}
return null;
}
@Override
public Method findFactoryMethod(Class<?>... expArgTypes)
{
// So, of all single-arg static methods:
for (AnnotatedMethod am : _classInfo.getStaticMethods()) {
// 24-Oct-2016, tatu: Better ensure it only takes 1 arg, no matter what
<CHANGES>
if (isFactoryMethod(am)) {
<CHANGEE>
// And must take one of expected arg types (or supertype)
Class<?> actualArgType = am.getRawParameterType(0);
for (Class<?> expArgType : expArgTypes) {
// And one that matches what we would pass in
if (actualArgType.isAssignableFrom(expArgType)) {
return am.getAnnotated();
}
}
}
}
return null;
}
{
/* First: return<SCANS>sonStdImpl(Object impl) {
return (impl != null) && isJacksonStdImpl(impl.getClass());
}
public static boolean isJacksonStdImpl(Class<?> implClass) {
return (implClass.getAnnotation(JacksonStdImpl.class) != null);
}
public static boolean isBogusClass(Class<?> cls) {
return (cls == Void.class || cls == Void.TYPE
|| cls == com.fasterxml.jackson.databind.annotation.NoClass.class);
}
public static boolean isNonStaticInnerClass(Class<?> cls) {
return !Modifier.isStatic(cls.getModifiers())
&& (getEnclosingClass(cls) != null);
}
/**
* @since 2.7
*/
public static boolean isObjectOrPrimitive(Class<?> cls) {
return (cls == CLS_OBJECT) || cls.isPrimitive();
}
/*
/**********************************************************
/* Access to various Class definition aspects; possibly
/* cacheable; and attempts was made in 2.7.0 - 2.7.7; however
/* unintented retention (~= memory leak) wrt [databind#1363]
/* resulted in removal of caching
/**********************************************************
*/
/**
* @since 2.7
*/
public static String getPackageName(Class<?> cls) {
Package pkg = cls.getPackage();
return (pkg == null) ? null : pkg.getName();
}
/**
* @since 2.7
*/
public static boolean hasEnclosingMethod(Class<?> cls) {
return !isObjectOrPrimitive(cls) && (cls.getEnclosingMethod() != null);
}
/**
* @since 2.7
*/
public static Field[] getDeclaredFields(Class<?> cls) {
return cls.getDeclaredFields();
}
/**
* @since 2.7
*/
public static Method[] getDeclaredMethods(Class<?> cls) {
return cls.getDeclaredMethods();
}
/**
* @since 2.7
*/
public static Annotation[] findClassAnnotations(Class<?> cls) {
if (isObjectOrPrimitive(cls)) {
return NO_ANNOTATIONS;
}
return cls.getDeclaredAnnotations();
}
/**
* @since 2.7
JacksonDatabind, 65
<FILEB>
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: (%s) %s",
re.getClass().getName(), re.getMessage());
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
if (isFactoryMethod(am) && am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
if (am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
} else {
return null;
}
return new StdKeyDeserializer(kind, raw);
}
@Override
public Object deserializeKey(String key, DeserializationContext ctxt)
throws IOException
{
if (key == null) { // is this even legal call?
return null;
}
try {
Object result = _parse(key, ctxt);
if (result != null) {
return result;
}
} catch (Exception re) {
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: %s", re.getMessage());
<CHANGEE>
}
if (_keyClass.isEnum() && ctxt.getConfig().isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
return null;
}
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation");
}
public Class<?> getKeyClass() { return _keyClass; }
protected Object _parse(String key, DeserializationContext ctxt) throws Exception
{
switch (_kind) {
case TYPE_BOOLEAN:
if ("true".equals(key)) {
<FILEE>
<FILEB>
*/
if (ac.getParameterCount() == 1) {
Class<?> actArg = ac.getRawParameterType(0);
for (Class<?> expArg : argTypes) {
if (expArg == actArg) {
return ac.getAnnotated();
}
}
}
}
return null;
}
@Override
public Method findFactoryMethod(Class<?>... expArgTypes)
{
// So, of all single-arg static methods:
for (AnnotatedMethod am : _classInfo.getStaticMethods()) {
// 24-Oct-2016, tatu: Better ensure it only takes 1 arg, no matter what
<CHANGES>
if (isFactoryMethod(am)) {
<CHANGEE>
// And must take one of expected arg types (or supertype)
Class<?> actualArgType = am.getRawParameterType(0);
for (Class<?> expArgType : expArgTypes) {
// And one that matches what we would pass in
if (actualArgType.isAssignableFrom(expArgType)) {
return am.getAnnotated();
}
}
}
}
return null;
}
{
/* First: return<SCANS>+SAMPLE_SPEC_VALUE_TN_ID4+"]\n"
+" }"
+"}"
;
/*
/**********************************************************
/* Helper classes (beans)
/**********************************************************
*/
/**
* Sample class from Jackson tutorial ("JacksonInFiveMinutes")
*/
protected static class FiveMinuteUser {
public enum Gender { MALE, FEMALE };
public static class Name
{
private String _first, _last;
public Name() { }
public Name(String f, String l) {
_first = f;
_last = l;
}
public String getFirst() { return _first; }
public String getLast() { return _last; }
public void setFirst(String s) { _first = s; }
public void setLast(String s) { _last = s; }
@Override
public boolean equals(Object o)
{
if (o == this) return true;
if (o == null || o.getClass() != getClass()) return false;
Name other = (Name) o;
return _first.equals(other._first) && _last.equals(other._last);
}
}
private Gender _gender;
private Name _name;
private boolean _isVerified;
private byte[] _userImage;
public FiveMinuteUser() { }
public FiveMinuteUser(String first, String last, boolean verified, Gender g, byte[] data)
{
_name = new Name(first, last);
_isVerified = verified;
_gender = g;
_userImage = data;
}
public Name getName() { return _name; }
public boolean isVerified() { return _isVerified; }
public Gender getGender() { return _gender; }
public byte[] getUserImage() { return _userImage; }
public void setName(Name n) { _name = n; }
public void setVerified(boolean b) { _isVerified = b; }
public void setGender(Gender g) { _gender = g; }
public void setUserImage(byte[] b) { _userImage = b; }
@Override
public boolean equals(Object o)
{
if (o == this) return true;
if (o == null || o.getClass() != getClass()) return
JacksonDatabind, 65
<FILEB>
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: (%s) %s",
re.getClass().getName(), re.getMessage());
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
if (isFactoryMethod(am) && am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
if (am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
} else {
return null;
}
return new StdKeyDeserializer(kind, raw);
}
@Override
public Object deserializeKey(String key, DeserializationContext ctxt)
throws IOException
{
if (key == null) { // is this even legal call?
return null;
}
try {
Object result = _parse(key, ctxt);
if (result != null) {
return result;
}
} catch (Exception re) {
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: %s", re.getMessage());
<CHANGEE>
}
if (_keyClass.isEnum() && ctxt.getConfig().isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
return null;
}
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation");
}
public Class<?> getKeyClass() { return _keyClass; }
protected Object _parse(String key, DeserializationContext ctxt) throws Exception
{
switch (_kind) {
case TYPE_BOOLEAN:
if ("true".equals(key)) {
<FILEE>
<FILEB>
*/
if (ac.getParameterCount() == 1) {
Class<?> actArg = ac.getRawParameterType(0);
for (Class<?> expArg : argTypes) {
if (expArg == actArg) {
return ac.getAnnotated();
}
}
}
}
return null;
}
@Override
public Method findFactoryMethod(Class<?>... expArgTypes)
{
// So, of all single-arg static methods:
for (AnnotatedMethod am : _classInfo.getStaticMethods()) {
// 24-Oct-2016, tatu: Better ensure it only takes 1 arg, no matter what
<CHANGES>
if (isFactoryMethod(am)) {
<CHANGEE>
// And must take one of expected arg types (or supertype)
Class<?> actualArgType = am.getRawParameterType(0);
for (Class<?> expArgType : expArgTypes) {
// And one that matches what we would pass in
if (actualArgType.isAssignableFrom(expArgType)) {
return am.getAnnotated();
}
}
}
}
return null;
}
{
/* First: return<SCANS> IOException
{
/* 23-Apr-2008, tatus: UTF-32 is not supported by JDK, have to
* use our own codec too (which is not optimal since there's
* a chance both encoder and decoder might have bugs, but ones
* that cancel each other out or such)
*/
byte[] data;
if (encoding.equalsIgnoreCase("UTF-32")) {
data = encodeInUTF32BE(input);
} else {
data = input.getBytes(encoding);
}
InputStream is = new ByteArrayInputStream(data);
return f.createParser(is);
}
/*
/**********************************************************
/* Additional assertion methods
/**********************************************************
*/
protected void assertToken(JsonToken expToken, JsonToken actToken)
{
if (actToken != expToken) {
fail("Expected token "+expToken+", current token "+actToken);
}
}
protected void assertToken(JsonToken expToken, JsonParser jp)
{
assertToken(expToken, jp.getCurrentToken());
}
protected void assertType(Object ob, Class<?> expType)
{
if (ob == null) {
fail("Expected an object of type "+expType.getName()+", got null");
}
Class<?> cls = ob.getClass();
if (!expType.isAssignableFrom(cls)) {
fail("Expected type "+expType.getName()+", got "+cls.getName());
}
}
protected void assertValidLocation(JsonLocation location) {
assertNotNull("Should have non-null location", location);
assertTrue("Should have positive line number", location.getLineNr() > 0);
}
protected void verifyException(Throwable e, String... matches)
{
String msg = e.getMessage();
String lmsg = (msg == null) ? "" : msg.toLowerCase();
for (String match : matches) {
String lmatch = match.toLowerCase();
if (lmsg.indexOf(lmatch) >= 0) {
return;
}
}
fail("Expected an exception with one of substrings ("+Arrays.asList(matches)+"): got one with message \""+msg+"\"");
}
/**
* Method that gets textual contents of the current token using
* available methods, and ensures results are consistent, before
* returning them
JacksonDatabind, 65
<FILEB>
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: (%s) %s",
re.getClass().getName(), re.getMessage());
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
if (isFactoryMethod(am) && am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
if (am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
} else {
return null;
}
return new StdKeyDeserializer(kind, raw);
}
@Override
public Object deserializeKey(String key, DeserializationContext ctxt)
throws IOException
{
if (key == null) { // is this even legal call?
return null;
}
try {
Object result = _parse(key, ctxt);
if (result != null) {
return result;
}
} catch (Exception re) {
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: %s", re.getMessage());
<CHANGEE>
}
if (_keyClass.isEnum() && ctxt.getConfig().isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
return null;
}
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation");
}
public Class<?> getKeyClass() { return _keyClass; }
protected Object _parse(String key, DeserializationContext ctxt) throws Exception
{
switch (_kind) {
case TYPE_BOOLEAN:
if ("true".equals(key)) {
<FILEE>
<FILEB>
*/
if (ac.getParameterCount() == 1) {
Class<?> actArg = ac.getRawParameterType(0);
for (Class<?> expArg : argTypes) {
if (expArg == actArg) {
return ac.getAnnotated();
}
}
}
}
return null;
}
@Override
public Method findFactoryMethod(Class<?>... expArgTypes)
{
// So, of all single-arg static methods:
for (AnnotatedMethod am : _classInfo.getStaticMethods()) {
// 24-Oct-2016, tatu: Better ensure it only takes 1 arg, no matter what
<CHANGES>
if (isFactoryMethod(am)) {
<CHANGEE>
// And must take one of expected arg types (or supertype)
Class<?> actualArgType = am.getRawParameterType(0);
for (Class<?> expArgType : expArgTypes) {
// And one that matches what we would pass in
if (actualArgType.isAssignableFrom(expArgType)) {
return am.getAnnotated();
}
}
}
}
return null;
}
{
/* First: return<SCANS> type.
*
* @param type Type to generate schema for (possibly with generic signature)
*
* @since 2.2
*/
public void acceptJsonFormatVisitor(JavaType type, JsonFormatVisitorWrapper visitor) throws JsonMappingException
{
if (type == null) {
throw new IllegalArgumentException("type must be provided");
}
_serializerProvider().acceptJsonFormatVisitor(type, visitor);
}
/**
* Since 2.6
*/
public void acceptJsonFormatVisitor(Class<?> rawType, JsonFormatVisitorWrapper visitor) throws JsonMappingException {
acceptJsonFormatVisitor(_config.constructType(rawType), visitor);
}
public boolean canSerialize(Class<?> type) {
return _serializerProvider().hasSerializerFor(type, null);
}
/**
* Method for checking whether instances of given type can be serialized,
* and optionally why (as per {@link Throwable} returned).
*
* @since 2.3
*/
public boolean canSerialize(Class<?> type, AtomicReference<Throwable> cause) {
return _serializerProvider().hasSerializerFor(type, cause);
}
/*
/**********************************************************
/* Overridable helper methods
/**********************************************************
*/
/**
* Overridable helper method used for constructing
* {@link SerializerProvider} to use for serialization.
*/
protected DefaultSerializerProvider _serializerProvider() {
return _serializerProvider.createInstance(_config, _serializerFactory);
}
/*
/**********************************************************
/* Internal methods
/**********************************************************
*/
/**
* @since 2.2
*/
protected void _verifySchemaType(FormatSchema schema)
{
if (schema != null) {
if (!_generatorFactory.canUseSchema(schema)) {
throw new IllegalArgumentException("Can not use FormatSchema of type "+schema.getClass().getName()
+" for format "+_generatorFactory.getFormatName());
}
}
}
/**
* Method called to configure the generator as necessary and then
* call write functionality
*/
protected final void _configAndWriteValue(JsonGenerator gen, Object value) throws IOException
{
_configureGenerator(gen);
if (_config.isEnabled(SerializationFeature.CLOSE_CLOSEABLE) && (value instanceof Closeable)) {
_writeCloseable(gen, value);
return;
}
try
JacksonDatabind, 65
<FILEB>
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: (%s) %s",
re.getClass().getName(), re.getMessage());
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
if (isFactoryMethod(am) && am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
if (am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
} else {
return null;
}
return new StdKeyDeserializer(kind, raw);
}
@Override
public Object deserializeKey(String key, DeserializationContext ctxt)
throws IOException
{
if (key == null) { // is this even legal call?
return null;
}
try {
Object result = _parse(key, ctxt);
if (result != null) {
return result;
}
} catch (Exception re) {
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: %s", re.getMessage());
<CHANGEE>
}
if (_keyClass.isEnum() && ctxt.getConfig().isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
return null;
}
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation");
}
public Class<?> getKeyClass() { return _keyClass; }
protected Object _parse(String key, DeserializationContext ctxt) throws Exception
{
switch (_kind) {
case TYPE_BOOLEAN:
if ("true".equals(key)) {
<FILEE>
<FILEB>
*/
if (ac.getParameterCount() == 1) {
Class<?> actArg = ac.getRawParameterType(0);
for (Class<?> expArg : argTypes) {
if (expArg == actArg) {
return ac.getAnnotated();
}
}
}
}
return null;
}
@Override
public Method findFactoryMethod(Class<?>... expArgTypes)
{
// So, of all single-arg static methods:
for (AnnotatedMethod am : _classInfo.getStaticMethods()) {
// 24-Oct-2016, tatu: Better ensure it only takes 1 arg, no matter what
<CHANGES>
if (isFactoryMethod(am)) {
<CHANGEE>
// And must take one of expected arg types (or supertype)
Class<?> actualArgType = am.getRawParameterType(0);
for (Class<?> expArgType : expArgTypes) {
// And one that matches what we would pass in
if (actualArgType.isAssignableFrom(expArgType)) {
return am.getAnnotated();
}
}
}
}
return null;
}
{
/* First: return<SCANS>valueInstantiator;
_delegateDeserializer = src._delegateDeserializer;
_propertyBasedCreator = src._propertyBasedCreator;
_beanProperties = beanProps;
_backRefs = src._backRefs;
_ignorableProps = src._ignorableProps;
_ignoreAllUnknown = src._ignoreAllUnknown;
_anySetter = src._anySetter;
_injectables = src._injectables;
_objectIdReader = src._objectIdReader;
_nonStandardCreation = src._nonStandardCreation;
_unwrappedPropertyHandler = src._unwrappedPropertyHandler;
_needViewProcesing = src._needViewProcesing;
_serializationShape = src._serializationShape;
_vanillaProcessing = src._vanillaProcessing;
}
@Override
public abstract JsonDeserializer<Object> unwrappingDeserializer(NameTransformer unwrapper);
public abstract BeanDeserializerBase withObjectIdReader(ObjectIdReader oir);
public abstract BeanDeserializerBase withIgnorableProperties(Set<String> ignorableProps);
/**
* Mutant factory method that custom sub-classes must override; not left as
* abstract to prevent more drastic backwards compatibility problems.
*
* @since 2.8
*/
public BeanDeserializerBase withBeanProperties(BeanPropertyMap props) {
throw new UnsupportedOperationException("Class "+getClass().getName()
+" does not override `withBeanProperties()`, needs to");
}
/**
* Fluent factory for creating a variant that can handle
* POJO output as a JSON Array. Implementations may ignore this request
* if no such input is possible.
*
* @since 2.1
*/
protected abstract BeanDeserializerBase asArrayDeserializer();
/*
/**********************************************************
/* Validation, post-processing
/**********************************************************
*/
/**
* Method called to finalize setup of this deserializer,
* after deserializer itself has been registered.
* This is needed to handle recursive and transitive dependencies.
*/
@Override
public void resolve(DeserializationContext ctxt)
throws JsonMappingException
{
ExternalTypeHandler.Builder extTypes = null;
// if ValueInstantiator can use "creator" approach, need to resolve it here...
SettableBeanProperty[] creatorProps;
if (_valueInstantiator.canCreateFromObjectWith()) {
creatorProps = _valueInstantiator.getFromObjectArguments(ctxt.getConfig());
JacksonDatabind, 65
<FILEB>
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: (%s) %s",
re.getClass().getName(), re.getMessage());
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
if (isFactoryMethod(am) && am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
if (am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
} else {
return null;
}
return new StdKeyDeserializer(kind, raw);
}
@Override
public Object deserializeKey(String key, DeserializationContext ctxt)
throws IOException
{
if (key == null) { // is this even legal call?
return null;
}
try {
Object result = _parse(key, ctxt);
if (result != null) {
return result;
}
} catch (Exception re) {
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: %s", re.getMessage());
<CHANGEE>
}
if (_keyClass.isEnum() && ctxt.getConfig().isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
return null;
}
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation");
}
public Class<?> getKeyClass() { return _keyClass; }
protected Object _parse(String key, DeserializationContext ctxt) throws Exception
{
switch (_kind) {
case TYPE_BOOLEAN:
if ("true".equals(key)) {
<FILEE>
<FILEB>
*/
if (ac.getParameterCount() == 1) {
Class<?> actArg = ac.getRawParameterType(0);
for (Class<?> expArg : argTypes) {
if (expArg == actArg) {
return ac.getAnnotated();
}
}
}
}
return null;
}
@Override
public Method findFactoryMethod(Class<?>... expArgTypes)
{
// So, of all single-arg static methods:
for (AnnotatedMethod am : _classInfo.getStaticMethods()) {
// 24-Oct-2016, tatu: Better ensure it only takes 1 arg, no matter what
<CHANGES>
if (isFactoryMethod(am)) {
<CHANGEE>
// And must take one of expected arg types (or supertype)
Class<?> actualArgType = am.getRawParameterType(0);
for (Class<?> expArgType : expArgTypes) {
// And one that matches what we would pass in
if (actualArgType.isAssignableFrom(expArgType)) {
return am.getAnnotated();
}
}
}
}
return null;
}
{
/* First: return<SCANS> setter" may also need to be resolved now
if (_anySetter != null && !_anySetter.hasValueDeserializer()) {
_anySetter = _anySetter.withValueDeserializer(findDeserializer(ctxt,
_anySetter.getType(), _anySetter.getProperty()));
}
// as well as delegate-based constructor:
if (_valueInstantiator.canCreateUsingDelegate()) {
JavaType delegateType = _valueInstantiator.getDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingDelegate()', but null for 'getDelegateType()'");
}
_delegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getDelegateCreator());
}
// and array-delegate-based constructor:
if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_beanType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
_arrayDelegateDeserializer = _findDelegateDeserializer(ctxt, delegateType,
_valueInstantiator.getArrayDelegateCreator());
}
// And now that we know CreatorProperty instances are also resolved can finally create the creator:
if (creatorProps != null) {
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
if (extTypes != null) {
// 21-Jun-2016, tatu: related to [databind#999], may need to link type ids too,
// so need to pass collected properties
_externalTypeIdHandler = extTypes.build(_beanProperties);
// we consider this non-standard, to offline handling
_nonStandardCreation = true;
}
_unwrappedPropertyHandler = unwrapped;
if (unwrapped != null) { // we consider this non-standard, to offline handling
_nonStandardCreation = true;
JacksonDatabind, 65
<FILEB>
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: (%s) %s",
re.getClass().getName(), re.getMessage());
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
if (isFactoryMethod(am) && am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
if (am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
} else {
return null;
}
return new StdKeyDeserializer(kind, raw);
}
@Override
public Object deserializeKey(String key, DeserializationContext ctxt)
throws IOException
{
if (key == null) { // is this even legal call?
return null;
}
try {
Object result = _parse(key, ctxt);
if (result != null) {
return result;
}
} catch (Exception re) {
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: %s", re.getMessage());
<CHANGEE>
}
if (_keyClass.isEnum() && ctxt.getConfig().isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
return null;
}
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation");
}
public Class<?> getKeyClass() { return _keyClass; }
protected Object _parse(String key, DeserializationContext ctxt) throws Exception
{
switch (_kind) {
case TYPE_BOOLEAN:
if ("true".equals(key)) {
<FILEE>
<FILEB>
*/
if (ac.getParameterCount() == 1) {
Class<?> actArg = ac.getRawParameterType(0);
for (Class<?> expArg : argTypes) {
if (expArg == actArg) {
return ac.getAnnotated();
}
}
}
}
return null;
}
@Override
public Method findFactoryMethod(Class<?>... expArgTypes)
{
// So, of all single-arg static methods:
for (AnnotatedMethod am : _classInfo.getStaticMethods()) {
// 24-Oct-2016, tatu: Better ensure it only takes 1 arg, no matter what
<CHANGES>
if (isFactoryMethod(am)) {
<CHANGEE>
// And must take one of expected arg types (or supertype)
Class<?> actualArgType = am.getRawParameterType(0);
for (Class<?> expArgType : expArgTypes) {
// And one that matches what we would pass in
if (actualArgType.isAssignableFrom(expArgType)) {
return am.getAnnotated();
}
}
}
}
return null;
}
{
/* First: return<SCANS> used as well... need to check that first
if (_objectIdReader != null) {
// 05-Aug-2013, tatu: May use native Object Id
if (p.canReadObjectId()) {
Object id = p.getObjectId();
if (id != null) {
Object ob = typeDeserializer.deserializeTypedFromObject(p, ctxt);
return _handleTypedObjectId(p, ctxt, ob, id);
}
}
// or, Object Ids Jackson explicitly sets
JsonToken t = p.getCurrentToken();
if (t != null) {
// Most commonly, a scalar (int id, uuid String, ...)
if (t.isScalarValue()) {
return deserializeFromObjectId(p, ctxt);
}
// but, with 2.5+, a simple Object-wrapped value also legal:
if (t == JsonToken.START_OBJECT) {
t = p.nextToken();
}
if ((t == JsonToken.FIELD_NAME) && _objectIdReader.maySerializeAsObject()
&& _objectIdReader.isValidReferencePropertyName(p.getCurrentName(), p)) {
return deserializeFromObjectId(p, ctxt);
}
}
}
// In future could check current token... for now this should be enough:
return typeDeserializer.deserializeTypedFromObject(p, ctxt);
}
/**
* Offlined method called to handle "native" Object Id that has been read
* and known to be associated with given deserialized POJO.
*
* @since 2.3
*/
protected Object _handleTypedObjectId(JsonParser p, DeserializationContext ctxt,
Object pojo, Object rawId)
throws IOException
{
// One more challenge: type of id may not be type of property we are expecting
// later on; specifically, numeric ids vs Strings.
JsonDeserializer<Object> idDeser = _objectIdReader.getDeserializer();
final Object id;
// Ok, this is bit ridiculous; let's see if conversion is needed:
if (idDeser.handledType() == rawId.getClass()) {
// nope: already same type
id = rawId;
} else {
id = _convertObjectId(p, ctxt, rawId, idDeser);
}
ReadableObjectId roid = ctxt.findObjectId(
JacksonDatabind, 65
<FILEB>
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: (%s) %s",
re.getClass().getName(), re.getMessage());
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
if (isFactoryMethod(am) && am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
if (am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
} else {
return null;
}
return new StdKeyDeserializer(kind, raw);
}
@Override
public Object deserializeKey(String key, DeserializationContext ctxt)
throws IOException
{
if (key == null) { // is this even legal call?
return null;
}
try {
Object result = _parse(key, ctxt);
if (result != null) {
return result;
}
} catch (Exception re) {
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: %s", re.getMessage());
<CHANGEE>
}
if (_keyClass.isEnum() && ctxt.getConfig().isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
return null;
}
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation");
}
public Class<?> getKeyClass() { return _keyClass; }
protected Object _parse(String key, DeserializationContext ctxt) throws Exception
{
switch (_kind) {
case TYPE_BOOLEAN:
if ("true".equals(key)) {
<FILEE>
<FILEB>
*/
if (ac.getParameterCount() == 1) {
Class<?> actArg = ac.getRawParameterType(0);
for (Class<?> expArg : argTypes) {
if (expArg == actArg) {
return ac.getAnnotated();
}
}
}
}
return null;
}
@Override
public Method findFactoryMethod(Class<?>... expArgTypes)
{
// So, of all single-arg static methods:
for (AnnotatedMethod am : _classInfo.getStaticMethods()) {
// 24-Oct-2016, tatu: Better ensure it only takes 1 arg, no matter what
<CHANGES>
if (isFactoryMethod(am)) {
<CHANGEE>
// And must take one of expected arg types (or supertype)
Class<?> actualArgType = am.getRawParameterType(0);
for (Class<?> expArgType : expArgTypes) {
// And one that matches what we would pass in
if (actualArgType.isAssignableFrom(expArgType)) {
return am.getAnnotated();
}
}
}
}
return null;
}
{
/* First: return<SCANS> bean);
}
return bean;
}
/**
* Helper method called to (try to) locate deserializer for given sub-type of
* type that this deserializer handles.
*/
protected JsonDeserializer<Object> _findSubclassDeserializer(DeserializationContext ctxt,
Object bean, TokenBuffer unknownTokens)
throws IOException
{
JsonDeserializer<Object> subDeser;
// First: maybe we have already created sub-type deserializer?
synchronized (this) {
subDeser = (_subDeserializers == null) ? null : _subDeserializers.get(new ClassKey(bean.getClass()));
}
if (subDeser != null) {
return subDeser;
}
// If not, maybe we can locate one. First, need provider
JavaType type = ctxt.constructType(bean.getClass());
/* 30-Jan-2012, tatu: Ideally we would be passing referring
* property; which in theory we could keep track of via
* ResolvableDeserializer (if we absolutely must...).
* But for now, let's not bother.
*/
// subDeser = ctxt.findValueDeserializer(type, _property);
subDeser = ctxt.findRootValueDeserializer(type);
// Also, need to cache it
if (subDeser != null) {
synchronized (this) {
if (_subDeserializers == null) {
_subDeserializers = new HashMap<ClassKey,JsonDeserializer<Object>>();;
}
_subDeserializers.put(new ClassKey(bean.getClass()), subDeser);
}
}
return subDeser;
}
/*
/**********************************************************
/* Helper methods for error reporting
/**********************************************************
*/
/**
* Method that will modify caught exception (passed in as argument)
* as necessary to include reference information, and to ensure it
* is a subtype of {@link IOException}, or an unchecked exception.
*<p>
* Rules for wrapping and unwrapping are bit complicated; essentially:
*<ul>
* <li>Errors are to be passed as is (if uncovered via unwrapping)
* <li>"Plain" IOExceptions (ones that are not of type
* {@link JsonMappingException} are to be passed as is
*</ul>
*/
JacksonDatabind, 65
<FILEB>
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: (%s) %s",
re.getClass().getName(), re.getMessage());
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
if (isFactoryMethod(am) && am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
if (am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
} else {
return null;
}
return new StdKeyDeserializer(kind, raw);
}
@Override
public Object deserializeKey(String key, DeserializationContext ctxt)
throws IOException
{
if (key == null) { // is this even legal call?
return null;
}
try {
Object result = _parse(key, ctxt);
if (result != null) {
return result;
}
} catch (Exception re) {
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: %s", re.getMessage());
<CHANGEE>
}
if (_keyClass.isEnum() && ctxt.getConfig().isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
return null;
}
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation");
}
public Class<?> getKeyClass() { return _keyClass; }
protected Object _parse(String key, DeserializationContext ctxt) throws Exception
{
switch (_kind) {
case TYPE_BOOLEAN:
if ("true".equals(key)) {
<FILEE>
<FILEB>
*/
if (ac.getParameterCount() == 1) {
Class<?> actArg = ac.getRawParameterType(0);
for (Class<?> expArg : argTypes) {
if (expArg == actArg) {
return ac.getAnnotated();
}
}
}
}
return null;
}
@Override
public Method findFactoryMethod(Class<?>... expArgTypes)
{
// So, of all single-arg static methods:
for (AnnotatedMethod am : _classInfo.getStaticMethods()) {
// 24-Oct-2016, tatu: Better ensure it only takes 1 arg, no matter what
<CHANGES>
if (isFactoryMethod(am)) {
<CHANGEE>
// And must take one of expected arg types (or supertype)
Class<?> actualArgType = am.getRawParameterType(0);
for (Class<?> expArgType : expArgTypes) {
// And one that matches what we would pass in
if (actualArgType.isAssignableFrom(expArgType)) {
return am.getAnnotated();
}
}
}
}
return null;
}
{
/* First: return<SCANS> * something returned by {@link #getUnknownTypeSerializer}, that is, something
* for which no regular serializer was found or constructed.
*
* @since 2.5
*/
public boolean isUnknownTypeSerializer(JsonSerializer<?> ser) {
if ((ser == _unknownTypeSerializer) || (ser == null)) {
return true;
}
// 23-Apr-2015, tatu: "empty" serializer is trickier; needs to consider
// error handling
if (isEnabled(SerializationFeature.FAIL_ON_EMPTY_BEANS)) {
if (ser.getClass() == UnknownSerializer.class) {
return true;
}
}
return false;
}
/*
/**********************************************************
/* Methods for creating instances based on annotations
/**********************************************************
*/
/**
* Method that can be called to construct and configure serializer instance,
* either given a {@link Class} to instantiate (with default constructor),
* or an uninitialized serializer instance.
* Either way, serialize will be properly resolved
* (via {@link com.fasterxml.jackson.databind.ser.ResolvableSerializer}) and/or contextualized
* (via {@link com.fasterxml.jackson.databind.ser.ContextualSerializer}) as necessary.
*
* @param annotated Annotated entity that contained definition
* @param serDef Serializer definition: either an instance or class
*/
public abstract JsonSerializer<Object> serializerInstance(Annotated annotated,
Object serDef)
throws JsonMappingException;
/*
/**********************************************************
/* Support for contextualization
/**********************************************************
*/
/**
* Method called for primary property serializers (ones
* directly created to serialize values of a POJO property),
* to handle details of resolving
* {@link ContextualSerializer} with given property context.
*
* @param property Property for which the given primary serializer is used; never null.
*
* @since 2.3
*/
public JsonSerializer<?> handlePrimaryContextualization(JsonSerializer<?> ser,
BeanProperty property)
throws JsonMappingException
{
if (ser != null) {
if (ser instanceof ContextualSerializer) {
ser = ((ContextualSerializer) ser).createContextual(this, property);
}
}
return ser;
}
/**
* Method called for secondary property serializers (
JacksonDatabind, 65
<FILEB>
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: (%s) %s",
re.getClass().getName(), re.getMessage());
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
if (isFactoryMethod(am) && am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
if (am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
} else {
return null;
}
return new StdKeyDeserializer(kind, raw);
}
@Override
public Object deserializeKey(String key, DeserializationContext ctxt)
throws IOException
{
if (key == null) { // is this even legal call?
return null;
}
try {
Object result = _parse(key, ctxt);
if (result != null) {
return result;
}
} catch (Exception re) {
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: %s", re.getMessage());
<CHANGEE>
}
if (_keyClass.isEnum() && ctxt.getConfig().isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
return null;
}
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation");
}
public Class<?> getKeyClass() { return _keyClass; }
protected Object _parse(String key, DeserializationContext ctxt) throws Exception
{
switch (_kind) {
case TYPE_BOOLEAN:
if ("true".equals(key)) {
<FILEE>
<FILEB>
*/
if (ac.getParameterCount() == 1) {
Class<?> actArg = ac.getRawParameterType(0);
for (Class<?> expArg : argTypes) {
if (expArg == actArg) {
return ac.getAnnotated();
}
}
}
}
return null;
}
@Override
public Method findFactoryMethod(Class<?>... expArgTypes)
{
// So, of all single-arg static methods:
for (AnnotatedMethod am : _classInfo.getStaticMethods()) {
// 24-Oct-2016, tatu: Better ensure it only takes 1 arg, no matter what
<CHANGES>
if (isFactoryMethod(am)) {
<CHANGEE>
// And must take one of expected arg types (or supertype)
Class<?> actualArgType = am.getRawParameterType(0);
for (Class<?> expArgType : expArgTypes) {
// And one that matches what we would pass in
if (actualArgType.isAssignableFrom(expArgType)) {
return am.getAnnotated();
}
}
}
}
return null;
}
{
/* First: return<SCANS>ones
* NOT directly created to serialize values of a POJO property
* but instead created as a dependant serializer -- such as value serializers
* for structured types, or serializers for root values)
* to handle details of resolving
* {@link ContextualDeserializer} with given property context.
* Given that these serializers are not directly related to given property
* (or, in case of root value property, to any property), annotations
* accessible may or may not be relevant.
*
* @param property Property for which serializer is used, if any; null
* when deserializing root values
*
* @since 2.3
*/
public JsonSerializer<?> handleSecondaryContextualization(JsonSerializer<?> ser,
BeanProperty property)
throws JsonMappingException
{
if (ser != null) {
if (ser instanceof ContextualSerializer) {
ser = ((ContextualSerializer) ser).createContextual(this, property);
}
}
return ser;
}
/*
/********************************************************
/* Convenience methods for serializing using default methods
/********************************************************
*/
/**
* Convenience method that will serialize given value (which can be
* null) using standard serializer locating functionality. It can
* be called for all values including field and Map values, but usually
* field values are best handled calling
* {@link #defaultSerializeField} instead.
*/
public final void defaultSerializeValue(Object value, JsonGenerator gen) throws IOException
{
if (value == null) {
if (_stdNullValueSerializer) { // minor perf optimization
gen.writeNull();
} else {
_nullValueSerializer.serialize(null, gen, this);
}
} else {
Class<?> cls = value.getClass();
findTypedValueSerializer(cls, true, null).serialize(value, gen, this);
}
}
/**
* Convenience method that will serialize given field with specified
* value. Value may be null. Serializer is done using the usual
* null) using standard serializer locating functionality.
*/
public final void defaultSerializeField(String fieldName, Object value, JsonGenerator gen)
throws IOException
{
gen.writeFieldName(fieldName);
if (value == null) {
/* Note: can't easily check for suppression at this point
* any more; caller must check it.
*/
if (_stdNullValueSerializer)
JacksonDatabind, 65
<FILEB>
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: (%s) %s",
re.getClass().getName(), re.getMessage());
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
if (isFactoryMethod(am) && am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
if (am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
} else {
return null;
}
return new StdKeyDeserializer(kind, raw);
}
@Override
public Object deserializeKey(String key, DeserializationContext ctxt)
throws IOException
{
if (key == null) { // is this even legal call?
return null;
}
try {
Object result = _parse(key, ctxt);
if (result != null) {
return result;
}
} catch (Exception re) {
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: %s", re.getMessage());
<CHANGEE>
}
if (_keyClass.isEnum() && ctxt.getConfig().isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
return null;
}
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation");
}
public Class<?> getKeyClass() { return _keyClass; }
protected Object _parse(String key, DeserializationContext ctxt) throws Exception
{
switch (_kind) {
case TYPE_BOOLEAN:
if ("true".equals(key)) {
<FILEE>
<FILEB>
*/
if (ac.getParameterCount() == 1) {
Class<?> actArg = ac.getRawParameterType(0);
for (Class<?> expArg : argTypes) {
if (expArg == actArg) {
return ac.getAnnotated();
}
}
}
}
return null;
}
@Override
public Method findFactoryMethod(Class<?>... expArgTypes)
{
// So, of all single-arg static methods:
for (AnnotatedMethod am : _classInfo.getStaticMethods()) {
// 24-Oct-2016, tatu: Better ensure it only takes 1 arg, no matter what
<CHANGES>
if (isFactoryMethod(am)) {
<CHANGEE>
// And must take one of expected arg types (or supertype)
Class<?> actualArgType = am.getRawParameterType(0);
for (Class<?> expArgType : expArgTypes) {
// And one that matches what we would pass in
if (actualArgType.isAssignableFrom(expArgType)) {
return am.getAnnotated();
}
}
}
}
return null;
}
{
/* First: return<SCANS> { // minor perf optimization
gen.writeNull();
} else {
_nullValueSerializer.serialize(null, gen, this);
}
} else {
Class<?> cls = value.getClass();
findTypedValueSerializer(cls, true, null).serialize(value, gen, this);
}
}
/**
* Method that will handle serialization of Date(-like) values, using
* {@link SerializationConfig} settings to determine expected serialization
* behavior.
* Note: date here means "full" date, that is, date AND time, as per
* Java convention (and not date-only values like in SQL)
*/
public final void defaultSerializeDateValue(long timestamp, JsonGenerator gen)
throws IOException
{
if (isEnabled(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)) {
gen.writeNumber(timestamp);
} else {
gen.writeString(_dateFormat().format(new Date(timestamp)));
}
}
/**
* Method that will handle serialization of Date(-like) values, using
* {@link SerializationConfig} settings to determine expected serialization
* behavior.
* Note: date here means "full" date, that is, date AND time, as per
* Java convention (and not date-only values like in SQL)
*/
public final void defaultSerializeDateValue(Date date, JsonGenerator gen) throws IOException
{
if (isEnabled(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)) {
gen.writeNumber(date.getTime());
} else {
gen.writeString(_dateFormat().format(date));
}
}
/**
* Method that will handle serialization of Dates used as {@link java.util.Map} keys,
* based on {@link SerializationFeature#WRITE_DATE_KEYS_AS_TIMESTAMPS}
* value (and if using textual representation, configured date format)
*/
public void defaultSerializeDateKey(long timestamp, JsonGenerator gen) throws IOException
{
if (isEnabled(SerializationFeature.WRITE_DATE_KEYS_AS_TIMESTAMPS)) {
gen.writeFieldName(String.valueOf(timestamp));
} else {
gen.writeFieldName(_dateFormat().format(new Date(timestamp)));
}
}
/**
* Method that will handle serialization of Dates used as {@link java.util.Map} keys
JacksonDatabind, 65
<FILEB>
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: (%s) %s",
re.getClass().getName(), re.getMessage());
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
if (isFactoryMethod(am) && am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
if (am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
} else {
return null;
}
return new StdKeyDeserializer(kind, raw);
}
@Override
public Object deserializeKey(String key, DeserializationContext ctxt)
throws IOException
{
if (key == null) { // is this even legal call?
return null;
}
try {
Object result = _parse(key, ctxt);
if (result != null) {
return result;
}
} catch (Exception re) {
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: %s", re.getMessage());
<CHANGEE>
}
if (_keyClass.isEnum() && ctxt.getConfig().isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
return null;
}
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation");
}
public Class<?> getKeyClass() { return _keyClass; }
protected Object _parse(String key, DeserializationContext ctxt) throws Exception
{
switch (_kind) {
case TYPE_BOOLEAN:
if ("true".equals(key)) {
<FILEE>
<FILEB>
*/
if (ac.getParameterCount() == 1) {
Class<?> actArg = ac.getRawParameterType(0);
for (Class<?> expArg : argTypes) {
if (expArg == actArg) {
return ac.getAnnotated();
}
}
}
}
return null;
}
@Override
public Method findFactoryMethod(Class<?>... expArgTypes)
{
// So, of all single-arg static methods:
for (AnnotatedMethod am : _classInfo.getStaticMethods()) {
// 24-Oct-2016, tatu: Better ensure it only takes 1 arg, no matter what
<CHANGES>
if (isFactoryMethod(am)) {
<CHANGEE>
// And must take one of expected arg types (or supertype)
Class<?> actualArgType = am.getRawParameterType(0);
for (Class<?> expArgType : expArgTypes) {
// And one that matches what we would pass in
if (actualArgType.isAssignableFrom(expArgType)) {
return am.getAnnotated();
}
}
}
}
return null;
}
{
/* First: return<SCANS> */
protected void _reportIncompatibleRootType(Object value, JavaType rootType) throws IOException
{
// One special case: allow primitive/wrapper type coercion
if (rootType.isPrimitive()) {
Class<?> wrapperType = ClassUtil.wrapperType(rootType.getRawClass());
// If it's just difference between wrapper, primitive, let it slide
if (wrapperType.isAssignableFrom(value.getClass())) {
return;
}
}
reportMappingProblem("Incompatible types: declared root type (%s) vs %s",
rootType, value.getClass().getName());
}
/**
* Method that will try to find a serializer, either from cache
* or by constructing one; but will not return an "unknown" serializer
* if this can not be done but rather returns null.
*
* @return Serializer if one can be found, null if not.
*/
protected JsonSerializer<Object> _findExplicitUntypedSerializer(Class<?> runtimeType)
throws JsonMappingException
{
// Fast lookup from local lookup thingy works?
JsonSerializer<Object> ser = _knownSerializers.untypedValueSerializer(runtimeType);
if (ser == null) {
// If not, maybe shared map already has it?
ser = _serializerCache.untypedValueSerializer(runtimeType);
if (ser == null) {
ser = _createAndCacheUntypedSerializer(runtimeType);
}
}
/* 18-Sep-2014, tatu: This is unfortunate patch over related change
* that pushes creation of "unknown type" serializer deeper down
* in BeanSerializerFactory; as a result, we need to "undo" creation
* here.
*/
if (isUnknownTypeSerializer(ser)) {
return null;
}
return ser;
}
/*
/**********************************************************
/* Low-level methods for actually constructing and initializing
/* serializers
/**********************************************************
*/
/**
* Method that will try to construct a value serializer; and if
* one is successfully created, cache it for reuse.
*/
protected JsonSerializer<Object> _createAndCacheUntypedSerializer(Class<?> rawType)
throws JsonMappingException
{
JavaType fullType = _config.constructType(rawType);
JsonSerializer<Object> ser;
try {
JacksonDatabind, 65
<FILEB>
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: (%s) %s",
re.getClass().getName(), re.getMessage());
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
if (isFactoryMethod(am) && am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
if (am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
} else {
return null;
}
return new StdKeyDeserializer(kind, raw);
}
@Override
public Object deserializeKey(String key, DeserializationContext ctxt)
throws IOException
{
if (key == null) { // is this even legal call?
return null;
}
try {
Object result = _parse(key, ctxt);
if (result != null) {
return result;
}
} catch (Exception re) {
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: %s", re.getMessage());
<CHANGEE>
}
if (_keyClass.isEnum() && ctxt.getConfig().isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
return null;
}
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation");
}
public Class<?> getKeyClass() { return _keyClass; }
protected Object _parse(String key, DeserializationContext ctxt) throws Exception
{
switch (_kind) {
case TYPE_BOOLEAN:
if ("true".equals(key)) {
<FILEE>
<FILEB>
*/
if (ac.getParameterCount() == 1) {
Class<?> actArg = ac.getRawParameterType(0);
for (Class<?> expArg : argTypes) {
if (expArg == actArg) {
return ac.getAnnotated();
}
}
}
}
return null;
}
@Override
public Method findFactoryMethod(Class<?>... expArgTypes)
{
// So, of all single-arg static methods:
for (AnnotatedMethod am : _classInfo.getStaticMethods()) {
// 24-Oct-2016, tatu: Better ensure it only takes 1 arg, no matter what
<CHANGES>
if (isFactoryMethod(am)) {
<CHANGEE>
// And must take one of expected arg types (or supertype)
Class<?> actualArgType = am.getRawParameterType(0);
for (Class<?> expArgType : expArgTypes) {
// And one that matches what we would pass in
if (actualArgType.isAssignableFrom(expArgType)) {
return am.getAnnotated();
}
}
}
}
return null;
}
{
/* First: return<SCANS> || ignorable.length == 0) ?
null : ArrayBuilders.arrayToSet(ignorable);
}
public void setIgnorableProperties(Set<String> ignorable) {
_ignorableProperties = (ignorable == null || ignorable.size() == 0) ?
null : ignorable;
}
/*
/**********************************************************
/* Validation, post-processing (ResolvableDeserializer)
/**********************************************************
*/
@Override
public void resolve(DeserializationContext ctxt) throws JsonMappingException
{
// May need to resolve types for delegate- and/or property-based creators:
if (_valueInstantiator != null) {
if (_valueInstantiator.canCreateUsingDelegate()) {
JavaType delegateType = _valueInstantiator.getDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid delegate-creator definition for "+_mapType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingDelegate()', but null for 'getDelegateType()'");
}
/* Theoretically should be able to get CreatorProperty for delegate
* parameter to pass; but things get tricky because DelegateCreator
* may contain injectable values. So, for now, let's pass nothing.
*/
_delegateDeserializer = findDeserializer(ctxt, delegateType, null);
} else if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid delegate-creator definition for "+_mapType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingDelegate()', but null for 'getArrayDelegateType()'");
}
_delegateDeserializer = findDeserializer(ctxt, delegateType, null);
}
}
if (_valueInstantiator.canCreateFromObjectWith()) {
SettableBeanProperty[] creatorProps = _valueInstantiator.getFromObjectArguments(ctxt.getConfig());
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
_standardStringKey = _isStdKeyDeser(_mapType, _keyDeserializer);
}
/**
* Method called to
JacksonDatabind, 65
<FILEB>
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: (%s) %s",
re.getClass().getName(), re.getMessage());
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
if (isFactoryMethod(am) && am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
if (am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
} else {
return null;
}
return new StdKeyDeserializer(kind, raw);
}
@Override
public Object deserializeKey(String key, DeserializationContext ctxt)
throws IOException
{
if (key == null) { // is this even legal call?
return null;
}
try {
Object result = _parse(key, ctxt);
if (result != null) {
return result;
}
} catch (Exception re) {
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: %s", re.getMessage());
<CHANGEE>
}
if (_keyClass.isEnum() && ctxt.getConfig().isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
return null;
}
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation");
}
public Class<?> getKeyClass() { return _keyClass; }
protected Object _parse(String key, DeserializationContext ctxt) throws Exception
{
switch (_kind) {
case TYPE_BOOLEAN:
if ("true".equals(key)) {
<FILEE>
<FILEB>
*/
if (ac.getParameterCount() == 1) {
Class<?> actArg = ac.getRawParameterType(0);
for (Class<?> expArg : argTypes) {
if (expArg == actArg) {
return ac.getAnnotated();
}
}
}
}
return null;
}
@Override
public Method findFactoryMethod(Class<?>... expArgTypes)
{
// So, of all single-arg static methods:
for (AnnotatedMethod am : _classInfo.getStaticMethods()) {
// 24-Oct-2016, tatu: Better ensure it only takes 1 arg, no matter what
<CHANGES>
if (isFactoryMethod(am)) {
<CHANGEE>
// And must take one of expected arg types (or supertype)
Class<?> actualArgType = am.getRawParameterType(0);
for (Class<?> expArgType : expArgTypes) {
// And one that matches what we would pass in
if (actualArgType.isAssignableFrom(expArgType)) {
return am.getAnnotated();
}
}
}
}
return null;
}
{
/* First: return<SCANS> pojo) throws IllegalArgumentException {
throw new IllegalArgumentException("Can not get virtual property '"+_name+"'");
}
/*
/**********************************************************
/* Extended API, generic
/**********************************************************
*/
public String getFullName() {
return getDeclaringClass().getName() + "#" + getName();
}
public int getAnnotationCount() { return 0; }
@Override
public int hashCode() {
return _name.hashCode();
}
@Override
public boolean equals(Object o) {
if (o == this) return true;
if (o == null || o.getClass() != getClass()) return false;
VirtualAnnotatedMember other = (VirtualAnnotatedMember) o;
return (other._declaringClass == _declaringClass)
&& other._name.equals(_name);
}
@Override
public String toString() {
return "[field "+getFullName()+"]";
}
}
JacksonDatabind, 65
<FILEB>
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: (%s) %s",
re.getClass().getName(), re.getMessage());
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
if (isFactoryMethod(am) && am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
if (am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
} else {
return null;
}
return new StdKeyDeserializer(kind, raw);
}
@Override
public Object deserializeKey(String key, DeserializationContext ctxt)
throws IOException
{
if (key == null) { // is this even legal call?
return null;
}
try {
Object result = _parse(key, ctxt);
if (result != null) {
return result;
}
} catch (Exception re) {
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: %s", re.getMessage());
<CHANGEE>
}
if (_keyClass.isEnum() && ctxt.getConfig().isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
return null;
}
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation");
}
public Class<?> getKeyClass() { return _keyClass; }
protected Object _parse(String key, DeserializationContext ctxt) throws Exception
{
switch (_kind) {
case TYPE_BOOLEAN:
if ("true".equals(key)) {
<FILEE>
<FILEB>
*/
if (ac.getParameterCount() == 1) {
Class<?> actArg = ac.getRawParameterType(0);
for (Class<?> expArg : argTypes) {
if (expArg == actArg) {
return ac.getAnnotated();
}
}
}
}
return null;
}
@Override
public Method findFactoryMethod(Class<?>... expArgTypes)
{
// So, of all single-arg static methods:
for (AnnotatedMethod am : _classInfo.getStaticMethods()) {
// 24-Oct-2016, tatu: Better ensure it only takes 1 arg, no matter what
<CHANGES>
if (isFactoryMethod(am)) {
<CHANGEE>
// And must take one of expected arg types (or supertype)
Class<?> actualArgType = am.getRawParameterType(0);
for (Class<?> expArgType : expArgTypes) {
// And one that matches what we would pass in
if (actualArgType.isAssignableFrom(expArgType)) {
return am.getAnnotated();
}
}
}
}
return null;
}
{
/* First: return<SCANS> properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS)",
value.getClass().getName());
}
}
JacksonDatabind, 65
<FILEB>
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: (%s) %s",
re.getClass().getName(), re.getMessage());
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
if (isFactoryMethod(am) && am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
if (am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
} else {
return null;
}
return new StdKeyDeserializer(kind, raw);
}
@Override
public Object deserializeKey(String key, DeserializationContext ctxt)
throws IOException
{
if (key == null) { // is this even legal call?
return null;
}
try {
Object result = _parse(key, ctxt);
if (result != null) {
return result;
}
} catch (Exception re) {
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: %s", re.getMessage());
<CHANGEE>
}
if (_keyClass.isEnum() && ctxt.getConfig().isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
return null;
}
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation");
}
public Class<?> getKeyClass() { return _keyClass; }
protected Object _parse(String key, DeserializationContext ctxt) throws Exception
{
switch (_kind) {
case TYPE_BOOLEAN:
if ("true".equals(key)) {
<FILEE>
<FILEB>
*/
if (ac.getParameterCount() == 1) {
Class<?> actArg = ac.getRawParameterType(0);
for (Class<?> expArg : argTypes) {
if (expArg == actArg) {
return ac.getAnnotated();
}
}
}
}
return null;
}
@Override
public Method findFactoryMethod(Class<?>... expArgTypes)
{
// So, of all single-arg static methods:
for (AnnotatedMethod am : _classInfo.getStaticMethods()) {
// 24-Oct-2016, tatu: Better ensure it only takes 1 arg, no matter what
<CHANGES>
if (isFactoryMethod(am)) {
<CHANGEE>
// And must take one of expected arg types (or supertype)
Class<?> actualArgType = am.getRawParameterType(0);
for (Class<?> expArgType : expArgTypes) {
// And one that matches what we would pass in
if (actualArgType.isAssignableFrom(expArgType)) {
return am.getAnnotated();
}
}
}
}
return null;
}
{
/* First: return<SCANS>
@Override
public StringBuilder getGenericSignature(StringBuilder sb)
{
_classSignature(_class, sb, false);
final int count = _bindings.size();
if (count > 0) {
sb.append('<');
for (int i = 0; i < count; ++i) {
sb = containedType(i).getGenericSignature(sb);
}
sb.append('>');
}
sb.append(';');
return sb;
}
/*
/**********************************************************
/* Internal methods
/**********************************************************
*/
/**
* Helper method we need to recursively build skeletal representations
* of superclasses.
*
* @since 2.7 -- remove when not needed (2.8?)
*/
private static JavaType _buildSuperClass(Class<?> superClass, TypeBindings b)
{
if (superClass == null) {
return null;
}
if (superClass == Object.class) {
return TypeFactory.unknownType();
}
JavaType superSuper = _buildSuperClass(superClass.getSuperclass(), b);
return new SimpleType(superClass, b,
superSuper, null, null, null, false);
}
/*
/**********************************************************
/* Standard methods
/**********************************************************
*/
@Override
public String toString()
{
StringBuilder sb = new StringBuilder(40);
sb.append("[simple type, class ").append(buildCanonicalName()).append(']');
return sb.toString();
}
@Override
public boolean equals(Object o)
{
if (o == this) return true;
if (o == null) return false;
if (o.getClass() != getClass()) return false;
SimpleType other = (SimpleType) o;
// Classes must be identical...
if (other._class != this._class) return false;
// And finally, generic bindings, if any
TypeBindings b1 = _bindings;
TypeBindings b2 = other._bindings;
return b1.equals(b2);
}
}
JacksonDatabind, 65
<FILEB>
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: (%s) %s",
re.getClass().getName(), re.getMessage());
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
if (isFactoryMethod(am) && am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
if (am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
} else {
return null;
}
return new StdKeyDeserializer(kind, raw);
}
@Override
public Object deserializeKey(String key, DeserializationContext ctxt)
throws IOException
{
if (key == null) { // is this even legal call?
return null;
}
try {
Object result = _parse(key, ctxt);
if (result != null) {
return result;
}
} catch (Exception re) {
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: %s", re.getMessage());
<CHANGEE>
}
if (_keyClass.isEnum() && ctxt.getConfig().isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
return null;
}
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation");
}
public Class<?> getKeyClass() { return _keyClass; }
protected Object _parse(String key, DeserializationContext ctxt) throws Exception
{
switch (_kind) {
case TYPE_BOOLEAN:
if ("true".equals(key)) {
<FILEE>
<FILEB>
*/
if (ac.getParameterCount() == 1) {
Class<?> actArg = ac.getRawParameterType(0);
for (Class<?> expArg : argTypes) {
if (expArg == actArg) {
return ac.getAnnotated();
}
}
}
}
return null;
}
@Override
public Method findFactoryMethod(Class<?>... expArgTypes)
{
// So, of all single-arg static methods:
for (AnnotatedMethod am : _classInfo.getStaticMethods()) {
// 24-Oct-2016, tatu: Better ensure it only takes 1 arg, no matter what
<CHANGES>
if (isFactoryMethod(am)) {
<CHANGEE>
// And must take one of expected arg types (or supertype)
Class<?> actualArgType = am.getRawParameterType(0);
for (Class<?> expArgType : expArgTypes) {
// And one that matches what we would pass in
if (actualArgType.isAssignableFrom(expArgType)) {
return am.getAnnotated();
}
}
}
}
return null;
}
{
/* First: return<SCANS>.append("UNRESOLVED");
} else {
// [databind#1301]: Typically resolves to a loop so short-cut
// and only include type-erased class
sb.append(_referencedType.getRawClass().getName());
}
return sb.toString();
}
@Override
public boolean equals(Object o) {
if (o == this) return true;
if (o == null) return false;
// Do NOT ever match unresolved references
if (_referencedType == null) {
return false;
}
return (o.getClass() == getClass()
&& _referencedType.equals(((ResolvedRecursiveType) o).getSelfReferencedType()));
}
}
JacksonDatabind, 65
<FILEB>
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: (%s) %s",
re.getClass().getName(), re.getMessage());
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
if (isFactoryMethod(am) && am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
if (am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
} else {
return null;
}
return new StdKeyDeserializer(kind, raw);
}
@Override
public Object deserializeKey(String key, DeserializationContext ctxt)
throws IOException
{
if (key == null) { // is this even legal call?
return null;
}
try {
Object result = _parse(key, ctxt);
if (result != null) {
return result;
}
} catch (Exception re) {
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: %s", re.getMessage());
<CHANGEE>
}
if (_keyClass.isEnum() && ctxt.getConfig().isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
return null;
}
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation");
}
public Class<?> getKeyClass() { return _keyClass; }
protected Object _parse(String key, DeserializationContext ctxt) throws Exception
{
switch (_kind) {
case TYPE_BOOLEAN:
if ("true".equals(key)) {
<FILEE>
<FILEB>
*/
if (ac.getParameterCount() == 1) {
Class<?> actArg = ac.getRawParameterType(0);
for (Class<?> expArg : argTypes) {
if (expArg == actArg) {
return ac.getAnnotated();
}
}
}
}
return null;
}
@Override
public Method findFactoryMethod(Class<?>... expArgTypes)
{
// So, of all single-arg static methods:
for (AnnotatedMethod am : _classInfo.getStaticMethods()) {
// 24-Oct-2016, tatu: Better ensure it only takes 1 arg, no matter what
<CHANGES>
if (isFactoryMethod(am)) {
<CHANGEE>
// And must take one of expected arg types (or supertype)
Class<?> actualArgType = am.getRawParameterType(0);
for (Class<?> expArgType : expArgTypes) {
// And one that matches what we would pass in
if (actualArgType.isAssignableFrom(expArgType)) {
return am.getAnnotated();
}
}
}
}
return null;
}
{
/* First: return<SCANS>Member m)
{
if (id == null) {
return;
}
if (_injectables == null) {
_injectables = new LinkedHashMap<Object, AnnotatedMember>();
}
AnnotatedMember prev = _injectables.put(id, m);
if (prev != null) {
String type = id.getClass().getName();
throw new IllegalArgumentException("Duplicate injectable value with id '"
+String.valueOf(id)+"' (of type "+type+")");
}
}
private PropertyName _propNameFromSimple(String simpleName) {
return PropertyName.construct(simpleName, null);
}
/*
/**********************************************************
/* Internal methods; removing ignored properties
/**********************************************************
*/
/**
* Method called to get rid of candidate properties that are marked
* as ignored.
*/
protected void _removeUnwantedProperties(Map<String, POJOPropertyBuilder> props)
{
Iterator<POJOPropertyBuilder> it = props.values().iterator();
while (it.hasNext()) {
POJOPropertyBuilder prop = it.next();
// First: if nothing visible, just remove altogether
if (!prop.anyVisible()) {
it.remove();
continue;
}
// Otherwise, check ignorals
if (prop.anyIgnorals()) {
// first: if one or more ignorals, and no explicit markers, remove the whole thing
if (!prop.isExplicitlyIncluded()) {
it.remove();
_collectIgnorals(prop.getName());
continue;
}
// otherwise just remove ones marked to be ignored
prop.removeIgnored();
if (!_forSerialization && !prop.couldDeserialize()) {
_collectIgnorals(prop.getName());
}
}
}
}
/**
* Method called to further get rid of unwanted individual accessors,
* based on read/write settings and rules for "pulling in" accessors
* (or not).
*/
protected void _removeUnwantedAccessor(Map<String, POJOPropertyBuilder> props)
{
final boolean inferMutators = _config.isEnabled(MapperFeature.INFER_PROPERTY_MUTATORS);
Iterator<POJOPropertyBuilder> it = props.values().iterator();
while (it.hasNext()) {
POJOPropertyBuilder prop = it.next();
JacksonDatabind, 65
<FILEB>
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: (%s) %s",
re.getClass().getName(), re.getMessage());
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
if (isFactoryMethod(am) && am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
if (am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
} else {
return null;
}
return new StdKeyDeserializer(kind, raw);
}
@Override
public Object deserializeKey(String key, DeserializationContext ctxt)
throws IOException
{
if (key == null) { // is this even legal call?
return null;
}
try {
Object result = _parse(key, ctxt);
if (result != null) {
return result;
}
} catch (Exception re) {
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: %s", re.getMessage());
<CHANGEE>
}
if (_keyClass.isEnum() && ctxt.getConfig().isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
return null;
}
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation");
}
public Class<?> getKeyClass() { return _keyClass; }
protected Object _parse(String key, DeserializationContext ctxt) throws Exception
{
switch (_kind) {
case TYPE_BOOLEAN:
if ("true".equals(key)) {
<FILEE>
<FILEB>
*/
if (ac.getParameterCount() == 1) {
Class<?> actArg = ac.getRawParameterType(0);
for (Class<?> expArg : argTypes) {
if (expArg == actArg) {
return ac.getAnnotated();
}
}
}
}
return null;
}
@Override
public Method findFactoryMethod(Class<?>... expArgTypes)
{
// So, of all single-arg static methods:
for (AnnotatedMethod am : _classInfo.getStaticMethods()) {
// 24-Oct-2016, tatu: Better ensure it only takes 1 arg, no matter what
<CHANGES>
if (isFactoryMethod(am)) {
<CHANGEE>
// And must take one of expected arg types (or supertype)
Class<?> actualArgType = am.getRawParameterType(0);
for (Class<?> expArgType : expArgTypes) {
// And one that matches what we would pass in
if (actualArgType.isAssignableFrom(expArgType)) {
return am.getAnnotated();
}
}
}
}
return null;
}
{
/* First: return<SCANS>) {
return (PropertyNamingStrategy) namingDef;
}
/* Alas, there's no way to force return type of "either class
* X or Y" -- need to throw an exception after the fact
*/
if (!(namingDef instanceof Class)) {
throw new IllegalStateException("AnnotationIntrospector returned PropertyNamingStrategy definition of type "
+namingDef.getClass().getName()+"; expected type PropertyNamingStrategy or Class<PropertyNamingStrategy> instead");
}
Class<?> namingClass = (Class<?>)namingDef;
// 09-Nov-2015, tatu: Need to consider pseudo-value of STD, which means "use default"
if (namingClass == PropertyNamingStrategy.class) {
return null;
}
if (!PropertyNamingStrategy.class.isAssignableFrom(namingClass)) {
throw new IllegalStateException("AnnotationIntrospector returned Class "
+namingClass.getName()+"; expected Class<PropertyNamingStrategy>");
}
HandlerInstantiator hi = _config.getHandlerInstantiator();
if (hi != null) {
PropertyNamingStrategy pns = hi.namingStrategyInstance(_config, _classDef, namingClass);
if (pns != null) {
return pns;
}
}
return (PropertyNamingStrategy) ClassUtil.createInstance(namingClass,
_config.canOverrideAccessModifiers());
}
protected void _updateCreatorProperty(POJOPropertyBuilder prop, List<POJOPropertyBuilder> creatorProperties) {
if (creatorProperties != null) {
for (int i = 0, len = creatorProperties.size(); i < len; ++i) {
if (creatorProperties.get(i).getInternalName().equals(prop.getInternalName())) {
creatorProperties.set(i, prop);
break;
}
}
}
}
}
JacksonDatabind, 65
<FILEB>
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: (%s) %s",
re.getClass().getName(), re.getMessage());
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
if (isFactoryMethod(am) && am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
if (am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
} else {
return null;
}
return new StdKeyDeserializer(kind, raw);
}
@Override
public Object deserializeKey(String key, DeserializationContext ctxt)
throws IOException
{
if (key == null) { // is this even legal call?
return null;
}
try {
Object result = _parse(key, ctxt);
if (result != null) {
return result;
}
} catch (Exception re) {
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: %s", re.getMessage());
<CHANGEE>
}
if (_keyClass.isEnum() && ctxt.getConfig().isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
return null;
}
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation");
}
public Class<?> getKeyClass() { return _keyClass; }
protected Object _parse(String key, DeserializationContext ctxt) throws Exception
{
switch (_kind) {
case TYPE_BOOLEAN:
if ("true".equals(key)) {
<FILEE>
<FILEB>
*/
if (ac.getParameterCount() == 1) {
Class<?> actArg = ac.getRawParameterType(0);
for (Class<?> expArg : argTypes) {
if (expArg == actArg) {
return ac.getAnnotated();
}
}
}
}
return null;
}
@Override
public Method findFactoryMethod(Class<?>... expArgTypes)
{
// So, of all single-arg static methods:
for (AnnotatedMethod am : _classInfo.getStaticMethods()) {
// 24-Oct-2016, tatu: Better ensure it only takes 1 arg, no matter what
<CHANGES>
if (isFactoryMethod(am)) {
<CHANGEE>
// And must take one of expected arg types (or supertype)
Class<?> actualArgType = am.getRawParameterType(0);
for (Class<?> expArgType : expArgTypes) {
// And one that matches what we would pass in
if (actualArgType.isAssignableFrom(expArgType)) {
return am.getAnnotated();
}
}
}
}
return null;
}
{
/* First: return<SCANS> = TypeBindings.emptyBindings();
} else {
bindings = TypeBindings.create(rawType, elemT);
}
return new CollectionLikeType(rawType, bindings,
_bogusSuperClass(rawType), null,
elemT, null, null, false);
}
/**
* Factory method that can be used to "upgrade" a basic type into collection-like
* one; usually done via {@link TypeModifier}
*
* @since 2.7
*/
public static CollectionLikeType upgradeFrom(JavaType baseType, JavaType elementType) {
// 19-Oct-2015, tatu: Not sure if and how other types could be used as base;
// will cross that bridge if and when need be
if (baseType instanceof TypeBase) {
return new CollectionLikeType((TypeBase) baseType, elementType);
}
throw new IllegalArgumentException("Can not upgrade from an instance of "+baseType.getClass());
}
@Override
@Deprecated // since 2.7
protected JavaType _narrow(Class<?> subclass) {
return new CollectionLikeType(subclass, _bindings,
_superClass, _superInterfaces, _elementType,
_valueHandler, _typeHandler, _asStatic);
}
@Override
public JavaType withContentType(JavaType contentType) {
if (_elementType == contentType) {
return this;
}
return new CollectionLikeType(_class, _bindings, _superClass, _superInterfaces,
contentType, _valueHandler, _typeHandler, _asStatic);
}
@Override
public CollectionLikeType withTypeHandler(Object h) {
return new CollectionLikeType(_class, _bindings,
_superClass, _superInterfaces, _elementType, _valueHandler, h, _asStatic);
}
@Override
public CollectionLikeType withContentTypeHandler(Object h)
{
return new CollectionLikeType(_class, _bindings,
_superClass, _superInterfaces, _elementType.withTypeHandler(h),
_valueHandler, _typeHandler, _asStatic);
}
@Override
public CollectionLikeType withValueHandler(Object h) {
return new CollectionLikeType(_class, _bindings,
_superClass, _superInterfaces, _elementType, h, _typeHandler, _asStatic
JacksonDatabind, 65
<FILEB>
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: (%s) %s",
re.getClass().getName(), re.getMessage());
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
if (isFactoryMethod(am) && am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
if (am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
} else {
return null;
}
return new StdKeyDeserializer(kind, raw);
}
@Override
public Object deserializeKey(String key, DeserializationContext ctxt)
throws IOException
{
if (key == null) { // is this even legal call?
return null;
}
try {
Object result = _parse(key, ctxt);
if (result != null) {
return result;
}
} catch (Exception re) {
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: %s", re.getMessage());
<CHANGEE>
}
if (_keyClass.isEnum() && ctxt.getConfig().isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
return null;
}
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation");
}
public Class<?> getKeyClass() { return _keyClass; }
protected Object _parse(String key, DeserializationContext ctxt) throws Exception
{
switch (_kind) {
case TYPE_BOOLEAN:
if ("true".equals(key)) {
<FILEE>
<FILEB>
*/
if (ac.getParameterCount() == 1) {
Class<?> actArg = ac.getRawParameterType(0);
for (Class<?> expArg : argTypes) {
if (expArg == actArg) {
return ac.getAnnotated();
}
}
}
}
return null;
}
@Override
public Method findFactoryMethod(Class<?>... expArgTypes)
{
// So, of all single-arg static methods:
for (AnnotatedMethod am : _classInfo.getStaticMethods()) {
// 24-Oct-2016, tatu: Better ensure it only takes 1 arg, no matter what
<CHANGES>
if (isFactoryMethod(am)) {
<CHANGEE>
// And must take one of expected arg types (or supertype)
Class<?> actualArgType = am.getRawParameterType(0);
for (Class<?> expArgType : expArgTypes) {
// And one that matches what we would pass in
if (actualArgType.isAssignableFrom(expArgType)) {
return am.getAnnotated();
}
}
}
}
return null;
}
{
/* First: return<SCANS> protected String buildCanonicalName() {
StringBuilder sb = new StringBuilder();
sb.append(_class.getName());
if (_elementType != null) {
sb.append('<');
sb.append(_elementType.toCanonical());
sb.append('>');
}
return sb.toString();
}
/*
/**********************************************************
/* Extended API
/**********************************************************
*/
/**
* Method that can be used for checking whether this type is a
* "real" Collection type; meaning whether it represents a parameterized
* subtype of {@link java.util.Collection} or just something that acts
* like one.
*/
public boolean isTrueCollectionType() {
return Collection.class.isAssignableFrom(_class);
}
/*
/**********************************************************
/* Standard methods
/**********************************************************
*/
@Override
public boolean equals(Object o)
{
if (o == this) return true;
if (o == null) return false;
if (o.getClass() != getClass()) return false;
CollectionLikeType other = (CollectionLikeType) o;
return (_class == other._class) && _elementType.equals(other._elementType);
}
@Override
public String toString()
{
return "[collection-like type; class "+_class.getName()+", contains "+_elementType+"]";
}
}
JacksonDatabind, 65
<FILEB>
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: (%s) %s",
re.getClass().getName(), re.getMessage());
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
if (isFactoryMethod(am) && am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
if (am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
} else {
return null;
}
return new StdKeyDeserializer(kind, raw);
}
@Override
public Object deserializeKey(String key, DeserializationContext ctxt)
throws IOException
{
if (key == null) { // is this even legal call?
return null;
}
try {
Object result = _parse(key, ctxt);
if (result != null) {
return result;
}
} catch (Exception re) {
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: %s", re.getMessage());
<CHANGEE>
}
if (_keyClass.isEnum() && ctxt.getConfig().isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
return null;
}
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation");
}
public Class<?> getKeyClass() { return _keyClass; }
protected Object _parse(String key, DeserializationContext ctxt) throws Exception
{
switch (_kind) {
case TYPE_BOOLEAN:
if ("true".equals(key)) {
<FILEE>
<FILEB>
*/
if (ac.getParameterCount() == 1) {
Class<?> actArg = ac.getRawParameterType(0);
for (Class<?> expArg : argTypes) {
if (expArg == actArg) {
return ac.getAnnotated();
}
}
}
}
return null;
}
@Override
public Method findFactoryMethod(Class<?>... expArgTypes)
{
// So, of all single-arg static methods:
for (AnnotatedMethod am : _classInfo.getStaticMethods()) {
// 24-Oct-2016, tatu: Better ensure it only takes 1 arg, no matter what
<CHANGES>
if (isFactoryMethod(am)) {
<CHANGEE>
// And must take one of expected arg types (or supertype)
Class<?> actualArgType = am.getRawParameterType(0);
for (Class<?> expArgType : expArgTypes) {
// And one that matches what we would pass in
if (actualArgType.isAssignableFrom(expArgType)) {
return am.getAnnotated();
}
}
}
}
return null;
}
{
/* First: return<SCANS> Class#getName}).
*
* @since 2.5
*/
public Object getTypeId() {
return getClass().getName();
}
/*
/**********************************************************
/* Life-cycle: registration
/**********************************************************
*/
/**
* Method called by {@link ObjectMapper} when module is registered.
* It is called to let module register functionality it provides,
* using callback methods passed-in context object exposes.
*/
public abstract void setupModule(SetupContext context);
/*
/**********************************************************
/* Helper types
/**********************************************************
*/
/**
* Interface Jackson exposes to modules for purpose of registering
* extended functionality.
* Usually implemented by {@link ObjectMapper}, but modules should
* NOT rely on this -- if they do require access to mapper instance,
* they need to call {@link SetupContext#getOwner} method.
*/
public static interface SetupContext
{
/*
/**********************************************************
/* Simple accessors
/**********************************************************
*/
/**
* Method that returns version information about {@link ObjectMapper}
* that implements this context. Modules can use this to choose
* different settings or initialization order; or even decide to fail
* set up completely if version is compatible with module.
*/
public Version getMapperVersion();
/**
* Fallback access method that allows modules to refer to the
* {@link ObjectMapper} that provided this context.
* It should NOT be needed by most modules; and ideally should
* not be used -- however, there may be cases where this may
* be necessary due to various design constraints.
*<p>
* NOTE: use of this method is discouraged, as it allows access to
* things Modules typically should not modify. It is included, however,
* to allow access to new features in cases where Module API
* has not yet been extended, or there are oversights.
*<p>
* Return value is chosen to not leak dependency to {@link ObjectMapper};
* however, instance will always be of that type.
* This is why return value is declared generic, to allow caller to
* specify context to often avoid casting.
*
* @since 2.0
*/
public <C extends ObjectCodec> C getOwner();
/**
* Accessor for finding {@link TypeFactory} that is currently configured
* by the context.
*<p>
JacksonDatabind, 65
<FILEB>
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: (%s) %s",
re.getClass().getName(), re.getMessage());
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
if (isFactoryMethod(am) && am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
if (am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
} else {
return null;
}
return new StdKeyDeserializer(kind, raw);
}
@Override
public Object deserializeKey(String key, DeserializationContext ctxt)
throws IOException
{
if (key == null) { // is this even legal call?
return null;
}
try {
Object result = _parse(key, ctxt);
if (result != null) {
return result;
}
} catch (Exception re) {
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: %s", re.getMessage());
<CHANGEE>
}
if (_keyClass.isEnum() && ctxt.getConfig().isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
return null;
}
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation");
}
public Class<?> getKeyClass() { return _keyClass; }
protected Object _parse(String key, DeserializationContext ctxt) throws Exception
{
switch (_kind) {
case TYPE_BOOLEAN:
if ("true".equals(key)) {
<FILEE>
<FILEB>
*/
if (ac.getParameterCount() == 1) {
Class<?> actArg = ac.getRawParameterType(0);
for (Class<?> expArg : argTypes) {
if (expArg == actArg) {
return ac.getAnnotated();
}
}
}
}
return null;
}
@Override
public Method findFactoryMethod(Class<?>... expArgTypes)
{
// So, of all single-arg static methods:
for (AnnotatedMethod am : _classInfo.getStaticMethods()) {
// 24-Oct-2016, tatu: Better ensure it only takes 1 arg, no matter what
<CHANGES>
if (isFactoryMethod(am)) {
<CHANGEE>
// And must take one of expected arg types (or supertype)
Class<?> actualArgType = am.getRawParameterType(0);
for (Class<?> expArgType : expArgTypes) {
// And one that matches what we would pass in
if (actualArgType.isAssignableFrom(expArgType)) {
return am.getAnnotated();
}
}
}
}
return null;
}
{
/* First: return<SCANS>databind#116]
// no need to modify further if we already had JavaType
return (JavaType) type;
}
else if (type instanceof GenericArrayType) {
resultType = _fromArrayType(context, (GenericArrayType) type, bindings);
}
else if (type instanceof TypeVariable<?>) {
resultType = _fromVariable(context, (TypeVariable<?>) type, bindings);
}
else if (type instanceof WildcardType) {
resultType = _fromWildcard(context, (WildcardType) type, bindings);
} else {
// sanity check
throw new IllegalArgumentException("Unrecognized Type: "+((type == null) ? "[null]" : type.toString()));
}
/* 21-Feb-2016, nateB/tatu: as per [databind#1129] (applied for 2.7.2),
* we do need to let all kinds of types to be refined, esp. for Scala module.
*/
if (_modifiers != null) {
TypeBindings b = resultType.getBindings();
if (b == null) {
b = EMPTY_BINDINGS;
}
for (TypeModifier mod : _modifiers) {
JavaType t = mod.modifyType(resultType, type, b, this);
if (t == null) {
throw new IllegalStateException(String.format(
"TypeModifier %s (of type %s) return null for type %s",
mod, mod.getClass().getName(), resultType));
}
resultType = t;
}
}
return resultType;
}
/**
* @param bindings Mapping of formal parameter declarations (for generic
* types) into actual types
*/
protected JavaType _fromClass(ClassStack context, Class<?> rawType, TypeBindings bindings)
{
// Very first thing: small set of core types we know well:
JavaType result = _findWellKnownSimple(rawType);
if (result != null) {
return result;
}
// Barring that, we may have recently constructed an instance
final Object key;
if ((bindings == null) || bindings.isEmpty()) {
key = rawType;
} else {
key = bindings.asKey(rawType);
}
result = _typeCache.get(key);
JacksonDatabind, 65
<FILEB>
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: (%s) %s",
re.getClass().getName(), re.getMessage());
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
if (isFactoryMethod(am) && am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
if (am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
} else {
return null;
}
return new StdKeyDeserializer(kind, raw);
}
@Override
public Object deserializeKey(String key, DeserializationContext ctxt)
throws IOException
{
if (key == null) { // is this even legal call?
return null;
}
try {
Object result = _parse(key, ctxt);
if (result != null) {
return result;
}
} catch (Exception re) {
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: %s", re.getMessage());
<CHANGEE>
}
if (_keyClass.isEnum() && ctxt.getConfig().isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
return null;
}
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation");
}
public Class<?> getKeyClass() { return _keyClass; }
protected Object _parse(String key, DeserializationContext ctxt) throws Exception
{
switch (_kind) {
case TYPE_BOOLEAN:
if ("true".equals(key)) {
<FILEE>
<FILEB>
*/
if (ac.getParameterCount() == 1) {
Class<?> actArg = ac.getRawParameterType(0);
for (Class<?> expArg : argTypes) {
if (expArg == actArg) {
return ac.getAnnotated();
}
}
}
}
return null;
}
@Override
public Method findFactoryMethod(Class<?>... expArgTypes)
{
// So, of all single-arg static methods:
for (AnnotatedMethod am : _classInfo.getStaticMethods()) {
// 24-Oct-2016, tatu: Better ensure it only takes 1 arg, no matter what
<CHANGES>
if (isFactoryMethod(am)) {
<CHANGEE>
// And must take one of expected arg types (or supertype)
Class<?> actualArgType = am.getRawParameterType(0);
for (Class<?> expArgType : expArgTypes) {
// And one that matches what we would pass in
if (actualArgType.isAssignableFrom(expArgType)) {
return am.getAnnotated();
}
}
}
}
return null;
}
{
/* First: return<SCANS> config)
{
if (_factoryConfig == config) {
return this;
}
/* 22-Nov-2010, tatu: Handling of subtypes is tricky if we do immutable-with-copy-ctor;
* and we pretty much have to here either choose between losing subtype instance
* when registering additional deserializers, or losing deserializers.
* Instead, let's actually just throw an error if this method is called when subtype
* has not properly overridden this method; this to indicate problem as soon as possible.
*/
if (getClass() != BeanDeserializerFactory.class) {
throw new IllegalStateException("Subtype of BeanDeserializerFactory ("+getClass().getName()
+") has not properly overridden method 'withAdditionalDeserializers': can not instantiate subtype with "
+"additional deserializer definitions");
}
return new BeanDeserializerFactory(config);
}
/*
/**********************************************************
/* DeserializerFactory API implementation
/**********************************************************
*/
/**
* Method that {@link DeserializerCache}s call to create a new
* deserializer for types other than Collections, Maps, arrays and
* enums.
*/
@Override
public JsonDeserializer<Object> createBeanDeserializer(DeserializationContext ctxt,
JavaType type, BeanDescription beanDesc)
throws JsonMappingException
{
final DeserializationConfig config = ctxt.getConfig();
// We may also have custom overrides:
JsonDeserializer<Object> custom = _findCustomBeanDeserializer(type, config, beanDesc);
if (custom != null) {
return custom;
}
/* One more thing to check: do we have an exception type
* (Throwable or its sub-classes)? If so, need slightly
* different handling.
*/
if (type.isThrowable()) {
return buildThrowableDeserializer(ctxt, type, beanDesc);
}
/* Or, for abstract types, may have alternate means for resolution
* (defaulting, materialization)
*/
// 29-Nov-2015, tatu: Also, filter out calls to primitive types, they are
// not something we could materialize anything for
if (type.isAbstract() && !type.isPrimitive() && !type.isEnumType()) {
// Let's make it possible to materialize abstract types.
JavaType concreteType = materializeAbstract
JacksonDatabind, 65
<FILEB>
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: (%s) %s",
re.getClass().getName(), re.getMessage());
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
if (isFactoryMethod(am) && am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
if (am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
} else {
return null;
}
return new StdKeyDeserializer(kind, raw);
}
@Override
public Object deserializeKey(String key, DeserializationContext ctxt)
throws IOException
{
if (key == null) { // is this even legal call?
return null;
}
try {
Object result = _parse(key, ctxt);
if (result != null) {
return result;
}
} catch (Exception re) {
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: %s", re.getMessage());
<CHANGEE>
}
if (_keyClass.isEnum() && ctxt.getConfig().isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
return null;
}
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation");
}
public Class<?> getKeyClass() { return _keyClass; }
protected Object _parse(String key, DeserializationContext ctxt) throws Exception
{
switch (_kind) {
case TYPE_BOOLEAN:
if ("true".equals(key)) {
<FILEE>
<FILEB>
*/
if (ac.getParameterCount() == 1) {
Class<?> actArg = ac.getRawParameterType(0);
for (Class<?> expArg : argTypes) {
if (expArg == actArg) {
return ac.getAnnotated();
}
}
}
}
return null;
}
@Override
public Method findFactoryMethod(Class<?>... expArgTypes)
{
// So, of all single-arg static methods:
for (AnnotatedMethod am : _classInfo.getStaticMethods()) {
// 24-Oct-2016, tatu: Better ensure it only takes 1 arg, no matter what
<CHANGES>
if (isFactoryMethod(am)) {
<CHANGEE>
// And must take one of expected arg types (or supertype)
Class<?> actualArgType = am.getRawParameterType(0);
for (Class<?> expArgType : expArgTypes) {
// And one that matches what we would pass in
if (actualArgType.isAssignableFrom(expArgType)) {
return am.getAnnotated();
}
}
}
}
return null;
}
{
/* First: return<SCANS>SerializerFactory f) {
super(src, config, f);
}
protected DefaultSerializerProvider(DefaultSerializerProvider src) {
super(src);
}
/**
* Method that sub-classes need to implement: used to create a non-blueprint instances
* from the blueprint.
* This is needed to retain state during serialization.
*/
public abstract DefaultSerializerProvider createInstance(SerializationConfig config,
SerializerFactory jsf);
/**
* Method needed to ensure that {@link ObjectMapper#copy} will work
* properly; specifically, that caches are cleared, but settings
* will otherwise remain identical; and that no sharing of state
* occurs.
*
* @since 2.5
*/
public DefaultSerializerProvider copy() {
throw new IllegalStateException("DefaultSerializerProvider sub-class not overriding copy()");
}
/*
/**********************************************************
/* Abstract method impls, factory methods
/**********************************************************
*/
@Override
public JsonSerializer<Object> serializerInstance(Annotated annotated, Object serDef) throws JsonMappingException
{
if (serDef == null) {
return null;
}
JsonSerializer<?> ser;
if (serDef instanceof JsonSerializer) {
ser = (JsonSerializer<?>) serDef;
} else {
/* Alas, there's no way to force return type of "either class
* X or Y" -- need to throw an exception after the fact
*/
if (!(serDef instanceof Class)) {
throw new IllegalStateException("AnnotationIntrospector returned serializer definition of type "
+serDef.getClass().getName()+"; expected type JsonSerializer or Class<JsonSerializer> instead");
}
Class<?> serClass = (Class<?>)serDef;
// there are some known "no class" markers to consider too:
if (serClass == JsonSerializer.None.class || ClassUtil.isBogusClass(serClass)) {
return null;
}
if (!JsonSerializer.class.isAssignableFrom(serClass)) {
throw new IllegalStateException("AnnotationIntrospector returned Class "
+serClass.getName()+"; expected Class<JsonSerializer>");
}
HandlerInstantiator hi = _config.getHandlerInstantiator();
ser = (hi == null) ? null : hi.serializerInstance(_config, annotated, serClass);
if (ser == null) {
ser = (JsonSerializer<?>) ClassUtil.createInstance(
JacksonDatabind, 65
<FILEB>
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: (%s) %s",
re.getClass().getName(), re.getMessage());
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
if (isFactoryMethod(am) && am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
if (am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
} else {
return null;
}
return new StdKeyDeserializer(kind, raw);
}
@Override
public Object deserializeKey(String key, DeserializationContext ctxt)
throws IOException
{
if (key == null) { // is this even legal call?
return null;
}
try {
Object result = _parse(key, ctxt);
if (result != null) {
return result;
}
} catch (Exception re) {
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: %s", re.getMessage());
<CHANGEE>
}
if (_keyClass.isEnum() && ctxt.getConfig().isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
return null;
}
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation");
}
public Class<?> getKeyClass() { return _keyClass; }
protected Object _parse(String key, DeserializationContext ctxt) throws Exception
{
switch (_kind) {
case TYPE_BOOLEAN:
if ("true".equals(key)) {
<FILEE>
<FILEB>
*/
if (ac.getParameterCount() == 1) {
Class<?> actArg = ac.getRawParameterType(0);
for (Class<?> expArg : argTypes) {
if (expArg == actArg) {
return ac.getAnnotated();
}
}
}
}
return null;
}
@Override
public Method findFactoryMethod(Class<?>... expArgTypes)
{
// So, of all single-arg static methods:
for (AnnotatedMethod am : _classInfo.getStaticMethods()) {
// 24-Oct-2016, tatu: Better ensure it only takes 1 arg, no matter what
<CHANGES>
if (isFactoryMethod(am)) {
<CHANGEE>
// And must take one of expected arg types (or supertype)
Class<?> actualArgType = am.getRawParameterType(0);
for (Class<?> expArgType : expArgTypes) {
// And one that matches what we would pass in
if (actualArgType.isAssignableFrom(expArgType)) {
return am.getAnnotated();
}
}
}
}
return null;
}
{
/* First: return<SCANS> given class.
*<p>
* Note that no Exceptions are thrown, including unchecked ones:
* implementations are to swallow exceptions if necessary.
*/
public boolean hasSerializerFor(Class<?> cls, AtomicReference<Throwable> cause)
{
// 07-Nov-2015, tatu: One special case, Object.class; will work only if
// empty beans are allowed or custom serializer registered. Easiest to
// check here.
if (cls == Object.class) {
if (!_config.isEnabled(SerializationFeature.FAIL_ON_EMPTY_BEANS)) {
return true;
}
}
try {
JsonSerializer<?> ser = _findExplicitUntypedSerializer(cls);
return (ser != null);
} catch (JsonMappingException e) {
if (cause != null) {
cause.set(e);
}
} catch (RuntimeException e) {
if (cause == null) { // earlier behavior
throw e;
}
cause.set(e);
}
return false;
}
/**
* Accessor for the {@link JsonGenerator} currently in use for serializing
* content. Null for blueprint instances; non-null for actual active
* provider instances.
*
* @since 2.8
*/
@Override
public JsonGenerator getGenerator() {
return _generator;
}
/*
/**********************************************************
/* Extended API called by ObjectMapper: value serialization
/**********************************************************
*/
/**
* The method to be called by {@link ObjectMapper} and {@link ObjectWriter}
* for serializing given value, using serializers that
* this provider has access to (via caching and/or creating new serializers
* as need be).
*/
public void serializeValue(JsonGenerator gen, Object value) throws IOException
{
_generator = gen;
if (value == null) {
_serializeNull(gen);
return;
}
Class<?> cls = value.getClass();
// true, since we do want to cache root-level typed serializers (ditto for null property)
final JsonSerializer<Object> ser = findTypedValueSerializer(cls, true, null);
// Ok: should we wrap result in an additional property ("root name")?
final boolean wrap;
PropertyName rootName = _config.getFullRootName();
JacksonDatabind, 65
<FILEB>
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: (%s) %s",
re.getClass().getName(), re.getMessage());
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
if (isFactoryMethod(am) && am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
if (am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
} else {
return null;
}
return new StdKeyDeserializer(kind, raw);
}
@Override
public Object deserializeKey(String key, DeserializationContext ctxt)
throws IOException
{
if (key == null) { // is this even legal call?
return null;
}
try {
Object result = _parse(key, ctxt);
if (result != null) {
return result;
}
} catch (Exception re) {
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: %s", re.getMessage());
<CHANGEE>
}
if (_keyClass.isEnum() && ctxt.getConfig().isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
return null;
}
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation");
}
public Class<?> getKeyClass() { return _keyClass; }
protected Object _parse(String key, DeserializationContext ctxt) throws Exception
{
switch (_kind) {
case TYPE_BOOLEAN:
if ("true".equals(key)) {
<FILEE>
<FILEB>
*/
if (ac.getParameterCount() == 1) {
Class<?> actArg = ac.getRawParameterType(0);
for (Class<?> expArg : argTypes) {
if (expArg == actArg) {
return ac.getAnnotated();
}
}
}
}
return null;
}
@Override
public Method findFactoryMethod(Class<?>... expArgTypes)
{
// So, of all single-arg static methods:
for (AnnotatedMethod am : _classInfo.getStaticMethods()) {
// 24-Oct-2016, tatu: Better ensure it only takes 1 arg, no matter what
<CHANGES>
if (isFactoryMethod(am)) {
<CHANGEE>
// And must take one of expected arg types (or supertype)
Class<?> actualArgType = am.getRawParameterType(0);
for (Class<?> expArgType : expArgTypes) {
// And one that matches what we would pass in
if (actualArgType.isAssignableFrom(expArgType)) {
return am.getAnnotated();
}
}
}
}
return null;
}
{
/* First: return<SCANS> if (rootName == null) { // not explicitly specified
wrap = _config.isEnabled(SerializationFeature.WRAP_ROOT_VALUE);
if (wrap) {
gen.writeStartObject();
PropertyName pname = _config.findRootName(value.getClass());
gen.writeFieldName(pname.simpleAsEncoded(_config));
}
} else if (rootName.isEmpty()) {
wrap = false;
} else { // [JACKSON-764]
// empty String means explicitly disabled; non-empty that it is enabled
wrap = true;
gen.writeStartObject();
gen.writeFieldName(rootName.getSimpleName());
}
try {
ser.serialize(value, gen, this);
if (wrap) {
gen.writeEndObject();
}
} catch (IOException ioe) { // As per [JACKSON-99], pass IOException and subtypes as-is
throw ioe;
} catch (Exception e) { // but wrap RuntimeExceptions, to get path information
String msg = e.getMessage();
if (msg == null) {
msg = "[no message for "+e.getClass().getName()+"]";
}
throw new JsonMappingException(gen, msg, e);
}
}
/**
* The method to be called by {@link ObjectMapper} and {@link ObjectWriter}
* for serializing given value (assumed to be of specified root type,
* instead of runtime type of value),
* using serializers that
* this provider has access to (via caching and/or creating new serializers
* as need be),
*
* @param rootType Type to use for locating serializer to use, instead of actual
* runtime type. Must be actual type, or one of its super types
*/
public void serializeValue(JsonGenerator gen, Object value, JavaType rootType) throws IOException
{
_generator = gen;
if (value == null) {
_serializeNull(gen);
return;
}
// Let's ensure types are compatible at this point
if (!rootType.getRawClass().isAssignableFrom(value.getClass())) {
_reportIncompatibleRootType(value, rootType);
}
// root value, not reached via property:
JsonSerializer<Object> ser = findTypedValueSerializer(rootType, true, null);
//
JacksonDatabind, 65
<FILEB>
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: (%s) %s",
re.getClass().getName(), re.getMessage());
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
if (isFactoryMethod(am) && am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
if (am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
} else {
return null;
}
return new StdKeyDeserializer(kind, raw);
}
@Override
public Object deserializeKey(String key, DeserializationContext ctxt)
throws IOException
{
if (key == null) { // is this even legal call?
return null;
}
try {
Object result = _parse(key, ctxt);
if (result != null) {
return result;
}
} catch (Exception re) {
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: %s", re.getMessage());
<CHANGEE>
}
if (_keyClass.isEnum() && ctxt.getConfig().isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
return null;
}
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation");
}
public Class<?> getKeyClass() { return _keyClass; }
protected Object _parse(String key, DeserializationContext ctxt) throws Exception
{
switch (_kind) {
case TYPE_BOOLEAN:
if ("true".equals(key)) {
<FILEE>
<FILEB>
*/
if (ac.getParameterCount() == 1) {
Class<?> actArg = ac.getRawParameterType(0);
for (Class<?> expArg : argTypes) {
if (expArg == actArg) {
return ac.getAnnotated();
}
}
}
}
return null;
}
@Override
public Method findFactoryMethod(Class<?>... expArgTypes)
{
// So, of all single-arg static methods:
for (AnnotatedMethod am : _classInfo.getStaticMethods()) {
// 24-Oct-2016, tatu: Better ensure it only takes 1 arg, no matter what
<CHANGES>
if (isFactoryMethod(am)) {
<CHANGEE>
// And must take one of expected arg types (or supertype)
Class<?> actualArgType = am.getRawParameterType(0);
for (Class<?> expArgType : expArgTypes) {
// And one that matches what we would pass in
if (actualArgType.isAssignableFrom(expArgType)) {
return am.getAnnotated();
}
}
}
}
return null;
}
{
/* First: return<SCANS> Ok: should we wrap result in an additional property ("root name")?
final boolean wrap;
PropertyName rootName = _config.getFullRootName();
if (rootName == null) { // not explicitly specified
wrap = _config.isEnabled(SerializationFeature.WRAP_ROOT_VALUE);
if (wrap) {
gen.writeStartObject();
PropertyName pname = _config.findRootName(value.getClass());
gen.writeFieldName(pname.simpleAsEncoded(_config));
}
} else if (rootName.isEmpty()) {
wrap = false;
} else {
// empty String means explicitly disabled; non-empty that it is enabled
wrap = true;
gen.writeStartObject();
gen.writeFieldName(rootName.getSimpleName());
}
try {
ser.serialize(value, gen, this);
if (wrap) {
gen.writeEndObject();
}
} catch (IOException ioe) { // no wrapping for IO (and derived)
throw ioe;
} catch (Exception e) { // but others do need to be, to get path etc
String msg = e.getMessage();
if (msg == null) {
msg = "[no message for "+e.getClass().getName()+"]";
}
reportMappingProblem(e, msg);
}
}
/**
* The method to be called by {@link ObjectWriter}
* for serializing given value (assumed to be of specified root type,
* instead of runtime type of value), when it may know specific
* {@link JsonSerializer} to use.
*
* @param rootType Type to use for locating serializer to use, instead of actual
* runtime type, if no serializer is passed
* @param ser Root Serializer to use, if not null
*
* @since 2.1
*/
public void serializeValue(JsonGenerator gen, Object value, JavaType rootType,
JsonSerializer<Object> ser) throws IOException
{
_generator = gen;
if (value == null) {
_serializeNull(gen);
return;
}
// Let's ensure types are compatible at this point
if ((rootType != null) && !rootType.getRawClass().isAssignableFrom(value.getClass())) {
_reportIncompatibleRootType(value, rootType);
}
// root value, not
JacksonDatabind, 65
<FILEB>
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: (%s) %s",
re.getClass().getName(), re.getMessage());
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
if (isFactoryMethod(am) && am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
if (am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
} else {
return null;
}
return new StdKeyDeserializer(kind, raw);
}
@Override
public Object deserializeKey(String key, DeserializationContext ctxt)
throws IOException
{
if (key == null) { // is this even legal call?
return null;
}
try {
Object result = _parse(key, ctxt);
if (result != null) {
return result;
}
} catch (Exception re) {
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: %s", re.getMessage());
<CHANGEE>
}
if (_keyClass.isEnum() && ctxt.getConfig().isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
return null;
}
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation");
}
public Class<?> getKeyClass() { return _keyClass; }
protected Object _parse(String key, DeserializationContext ctxt) throws Exception
{
switch (_kind) {
case TYPE_BOOLEAN:
if ("true".equals(key)) {
<FILEE>
<FILEB>
*/
if (ac.getParameterCount() == 1) {
Class<?> actArg = ac.getRawParameterType(0);
for (Class<?> expArg : argTypes) {
if (expArg == actArg) {
return ac.getAnnotated();
}
}
}
}
return null;
}
@Override
public Method findFactoryMethod(Class<?>... expArgTypes)
{
// So, of all single-arg static methods:
for (AnnotatedMethod am : _classInfo.getStaticMethods()) {
// 24-Oct-2016, tatu: Better ensure it only takes 1 arg, no matter what
<CHANGES>
if (isFactoryMethod(am)) {
<CHANGEE>
// And must take one of expected arg types (or supertype)
Class<?> actualArgType = am.getRawParameterType(0);
for (Class<?> expArgType : expArgTypes) {
// And one that matches what we would pass in
if (actualArgType.isAssignableFrom(expArgType)) {
return am.getAnnotated();
}
}
}
}
return null;
}
{
/* First: return<SCANS> reached via property:
if (ser == null) {
ser = findTypedValueSerializer(rootType, true, null);
}
// Ok: should we wrap result in an additional property ("root name")?
final boolean wrap;
PropertyName rootName = _config.getFullRootName();
if (rootName == null) { // not explicitly specified
// [JACKSON-163]
wrap = _config.isEnabled(SerializationFeature.WRAP_ROOT_VALUE);
if (wrap) {
gen.writeStartObject();
PropertyName pname = (rootType == null)
? _config.findRootName(value.getClass())
: _config.findRootName(rootType);
gen.writeFieldName(pname.simpleAsEncoded(_config));
}
} else if (rootName.isEmpty()) {
wrap = false;
} else { // [JACKSON-764]
// empty String means explicitly disabled; non-empty that it is enabled
wrap = true;
gen.writeStartObject();
gen.writeFieldName(rootName.getSimpleName());
}
try {
ser.serialize(value, gen, this);
if (wrap) {
gen.writeEndObject();
}
} catch (IOException ioe) { // no wrapping for IO (and derived)
throw ioe;
} catch (Exception e) { // but others do need to be, to get path etc
String msg = e.getMessage();
if (msg == null) {
msg = "[no message for "+e.getClass().getName()+"]";
}
reportMappingProblem(e, msg);
}
}
/**
* Alternate serialization call used for polymorphic types, when {@link TypeSerializer}
* is already known, but the actual serializer may or may not be.
*
* @since 2.6
*/
public void serializePolymorphic(JsonGenerator gen, Object value, JavaType rootType,
JsonSerializer<Object> valueSer, TypeSerializer typeSer)
throws IOException
{
_generator = gen;
if (value == null) {
_serializeNull(gen);
return;
}
// Let's ensure types are compatible at this point
if ((rootType != null) && !rootType.getRawClass().isAssignableFrom(value.getClass())) {
_reportIncompatible
JacksonDatabind, 65
<FILEB>
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: (%s) %s",
re.getClass().getName(), re.getMessage());
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
if (isFactoryMethod(am) && am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
if (am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
} else {
return null;
}
return new StdKeyDeserializer(kind, raw);
}
@Override
public Object deserializeKey(String key, DeserializationContext ctxt)
throws IOException
{
if (key == null) { // is this even legal call?
return null;
}
try {
Object result = _parse(key, ctxt);
if (result != null) {
return result;
}
} catch (Exception re) {
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: %s", re.getMessage());
<CHANGEE>
}
if (_keyClass.isEnum() && ctxt.getConfig().isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
return null;
}
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation");
}
public Class<?> getKeyClass() { return _keyClass; }
protected Object _parse(String key, DeserializationContext ctxt) throws Exception
{
switch (_kind) {
case TYPE_BOOLEAN:
if ("true".equals(key)) {
<FILEE>
<FILEB>
*/
if (ac.getParameterCount() == 1) {
Class<?> actArg = ac.getRawParameterType(0);
for (Class<?> expArg : argTypes) {
if (expArg == actArg) {
return ac.getAnnotated();
}
}
}
}
return null;
}
@Override
public Method findFactoryMethod(Class<?>... expArgTypes)
{
// So, of all single-arg static methods:
for (AnnotatedMethod am : _classInfo.getStaticMethods()) {
// 24-Oct-2016, tatu: Better ensure it only takes 1 arg, no matter what
<CHANGES>
if (isFactoryMethod(am)) {
<CHANGEE>
// And must take one of expected arg types (or supertype)
Class<?> actualArgType = am.getRawParameterType(0);
for (Class<?> expArgType : expArgTypes) {
// And one that matches what we would pass in
if (actualArgType.isAssignableFrom(expArgType)) {
return am.getAnnotated();
}
}
}
}
return null;
}
{
/* First: return<SCANS>RootType(value, rootType);
}
/* 12-Jun-2015, tatu: nominal root type is necessary for Maps at least;
* possibly collections, but can cause problems for other polymorphic
* types. We really need to distinguish between serialization type,
* base type; but right we don't. Hence this check
*/
if (valueSer == null) {
if ((rootType != null) && rootType.isContainerType()) {
valueSer = findValueSerializer(rootType, null);
} else {
valueSer = findValueSerializer(value.getClass(), null);
}
}
final boolean wrap;
PropertyName rootName = _config.getFullRootName();
if (rootName == null) {
wrap = _config.isEnabled(SerializationFeature.WRAP_ROOT_VALUE);
if (wrap) {
gen.writeStartObject();
PropertyName pname = _config.findRootName(value.getClass());
gen.writeFieldName(pname.simpleAsEncoded(_config));
}
} else if (rootName.isEmpty()) {
wrap = false;
} else {
wrap = true;
gen.writeStartObject();
gen.writeFieldName(rootName.getSimpleName());
}
try {
valueSer.serializeWithType(value, gen, this, typeSer);
if (wrap) {
gen.writeEndObject();
}
} catch (IOException ioe) { // no wrapping for IO (and derived)
throw ioe;
} catch (Exception e) { // but others do need to be, to get path etc
String msg = e.getMessage();
if (msg == null) {
msg = "[no message for "+e.getClass().getName()+"]";
}
reportMappingProblem(e, msg);
}
}
/**
* @deprecated since 2.6; remove from 2.7 or later
*/
@Deprecated
public void serializePolymorphic(JsonGenerator gen, Object value, TypeSerializer typeSer)
throws IOException
{
JavaType t = (value == null) ? null : _config.constructType(value.getClass());
serializePolymorphic(gen, value, t, null, typeSer);
}
/**
* Helper method called when root value to serialize is null
*
* @
JacksonDatabind, 65
<FILEB>
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: (%s) %s",
re.getClass().getName(), re.getMessage());
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
if (isFactoryMethod(am) && am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
if (am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
} else {
return null;
}
return new StdKeyDeserializer(kind, raw);
}
@Override
public Object deserializeKey(String key, DeserializationContext ctxt)
throws IOException
{
if (key == null) { // is this even legal call?
return null;
}
try {
Object result = _parse(key, ctxt);
if (result != null) {
return result;
}
} catch (Exception re) {
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: %s", re.getMessage());
<CHANGEE>
}
if (_keyClass.isEnum() && ctxt.getConfig().isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
return null;
}
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation");
}
public Class<?> getKeyClass() { return _keyClass; }
protected Object _parse(String key, DeserializationContext ctxt) throws Exception
{
switch (_kind) {
case TYPE_BOOLEAN:
if ("true".equals(key)) {
<FILEE>
<FILEB>
*/
if (ac.getParameterCount() == 1) {
Class<?> actArg = ac.getRawParameterType(0);
for (Class<?> expArg : argTypes) {
if (expArg == actArg) {
return ac.getAnnotated();
}
}
}
}
return null;
}
@Override
public Method findFactoryMethod(Class<?>... expArgTypes)
{
// So, of all single-arg static methods:
for (AnnotatedMethod am : _classInfo.getStaticMethods()) {
// 24-Oct-2016, tatu: Better ensure it only takes 1 arg, no matter what
<CHANGES>
if (isFactoryMethod(am)) {
<CHANGEE>
// And must take one of expected arg types (or supertype)
Class<?> actualArgType = am.getRawParameterType(0);
for (Class<?> expArgType : expArgTypes) {
// And one that matches what we would pass in
if (actualArgType.isAssignableFrom(expArgType)) {
return am.getAnnotated();
}
}
}
}
return null;
}
{
/* First: return<SCANS>since 2.3
*/
protected void _serializeNull(JsonGenerator gen) throws IOException
{
JsonSerializer<Object> ser = getDefaultNullValueSerializer();
try {
ser.serialize(null, gen, this);
} catch (IOException ioe) { // no wrapping for IO (and derived)
throw ioe;
} catch (Exception e) { // but others do need to be, to get path etc
String msg = e.getMessage();
if (msg == null) {
msg = "[no message for "+e.getClass().getName()+"]";
}
reportMappingProblem(e, msg);
}
}
/*
/********************************************************
/* Access to caching details
/********************************************************
*/
/**
* Method that can be used to determine how many serializers this
* provider is caching currently
* (if it does caching: default implementation does)
* Exact count depends on what kind of serializers get cached;
* default implementation caches all serializers, including ones that
* are eagerly constructed (for optimal access speed)
*<p>
* The main use case for this method is to allow conditional flushing of
* serializer cache, if certain number of entries is reached.
*/
public int cachedSerializersCount() {
return _serializerCache.size();
}
/**
* Method that will drop all serializers currently cached by this provider.
* This can be used to remove memory usage (in case some serializers are
* only used once or so), or to force re-construction of serializers after
* configuration changes for mapper than owns the provider.
*/
public void flushCachedSerializers() {
_serializerCache.flush();
}
/*
/**********************************************************
/* Extended API called by ObjectMapper: other
/**********************************************************
*/
/**
* The method to be called by {@link ObjectMapper} and {@link ObjectWriter}
* to to expose the format of the given to to the given visitor
*
* @param javaType The type for which to generate format
* @param visitor the visitor to accept the format
*/
public void acceptJsonFormatVisitor(JavaType javaType, JsonFormatVisitorWrapper visitor)
throws JsonMappingException
{
if (javaType == null) {
throw new IllegalArgumentException("A class must be provided");
}
/* no need for embedded type information for JSON schema generation (all
* type information it needs
JacksonDatabind, 65
<FILEB>
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: (%s) %s",
re.getClass().getName(), re.getMessage());
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
if (isFactoryMethod(am) && am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
if (am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
} else {
return null;
}
return new StdKeyDeserializer(kind, raw);
}
@Override
public Object deserializeKey(String key, DeserializationContext ctxt)
throws IOException
{
if (key == null) { // is this even legal call?
return null;
}
try {
Object result = _parse(key, ctxt);
if (result != null) {
return result;
}
} catch (Exception re) {
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: %s", re.getMessage());
<CHANGEE>
}
if (_keyClass.isEnum() && ctxt.getConfig().isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
return null;
}
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation");
}
public Class<?> getKeyClass() { return _keyClass; }
protected Object _parse(String key, DeserializationContext ctxt) throws Exception
{
switch (_kind) {
case TYPE_BOOLEAN:
if ("true".equals(key)) {
<FILEE>
<FILEB>
*/
if (ac.getParameterCount() == 1) {
Class<?> actArg = ac.getRawParameterType(0);
for (Class<?> expArg : argTypes) {
if (expArg == actArg) {
return ac.getAnnotated();
}
}
}
}
return null;
}
@Override
public Method findFactoryMethod(Class<?>... expArgTypes)
{
// So, of all single-arg static methods:
for (AnnotatedMethod am : _classInfo.getStaticMethods()) {
// 24-Oct-2016, tatu: Better ensure it only takes 1 arg, no matter what
<CHANGES>
if (isFactoryMethod(am)) {
<CHANGEE>
// And must take one of expected arg types (or supertype)
Class<?> actualArgType = am.getRawParameterType(0);
for (Class<?> expArgType : expArgTypes) {
// And one that matches what we would pass in
if (actualArgType.isAssignableFrom(expArgType)) {
return am.getAnnotated();
}
}
}
}
return null;
}
{
/* First: return<SCANS> is accessible via "untyped" serializer)
*/
visitor.setProvider(this);
findValueSerializer(javaType, null).acceptJsonFormatVisitor(visitor, javaType);
}
/**
* The method to be called by {@link ObjectMapper}
* to generate <a href="http://json-schema.org/">JSON schema</a> for
* given type.
*
* @param type The type for which to generate schema
*
* @deprecated Should not be used any more
*/
@Deprecated // since 2.6
public com.fasterxml.jackson.databind.jsonschema.JsonSchema generateJsonSchema(Class<?> type)
throws JsonMappingException
{
if (type == null) {
throw new IllegalArgumentException("A class must be provided");
}
/* no need for embedded type information for JSON schema generation (all
* type information it needs is accessible via "untyped" serializer)
*/
JsonSerializer<Object> ser = findValueSerializer(type, null);
JsonNode schemaNode = (ser instanceof SchemaAware) ?
((SchemaAware) ser).getSchema(this, null) : com.fasterxml.jackson.databind.jsonschema.JsonSchema.getDefaultSchemaNode();
if (!(schemaNode instanceof ObjectNode)) {
throw new IllegalArgumentException("Class " + type.getName()
+" would not be serialized as a JSON object and therefore has no schema");
}
return new com.fasterxml.jackson.databind.jsonschema.JsonSchema((ObjectNode) schemaNode);
}
/*
/**********************************************************
/* Helper classes
/**********************************************************
*/
/**
* Concrete implementation that defines factory method(s),
* defined as final.
*/
public final static class Impl extends DefaultSerializerProvider {
private static final long serialVersionUID = 1L;
public Impl() { super(); }
public Impl(Impl src) { super(src); }
protected Impl(SerializerProvider src, SerializationConfig config,
SerializerFactory f) {
super(src, config, f);
}
@Override
public DefaultSerializerProvider copy()
{
if (getClass() != Impl.class) {
return super.copy();
}
return new Impl(this);
}
@Override
public Impl createInstance(SerializationConfig config, SerializerFactory jsf) {
return new Impl(this, config
JacksonDatabind, 65
<FILEB>
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: (%s) %s",
re.getClass().getName(), re.getMessage());
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
if (isFactoryMethod(am) && am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
if (am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
} else {
return null;
}
return new StdKeyDeserializer(kind, raw);
}
@Override
public Object deserializeKey(String key, DeserializationContext ctxt)
throws IOException
{
if (key == null) { // is this even legal call?
return null;
}
try {
Object result = _parse(key, ctxt);
if (result != null) {
return result;
}
} catch (Exception re) {
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: %s", re.getMessage());
<CHANGEE>
}
if (_keyClass.isEnum() && ctxt.getConfig().isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
return null;
}
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation");
}
public Class<?> getKeyClass() { return _keyClass; }
protected Object _parse(String key, DeserializationContext ctxt) throws Exception
{
switch (_kind) {
case TYPE_BOOLEAN:
if ("true".equals(key)) {
<FILEE>
<FILEB>
*/
if (ac.getParameterCount() == 1) {
Class<?> actArg = ac.getRawParameterType(0);
for (Class<?> expArg : argTypes) {
if (expArg == actArg) {
return ac.getAnnotated();
}
}
}
}
return null;
}
@Override
public Method findFactoryMethod(Class<?>... expArgTypes)
{
// So, of all single-arg static methods:
for (AnnotatedMethod am : _classInfo.getStaticMethods()) {
// 24-Oct-2016, tatu: Better ensure it only takes 1 arg, no matter what
<CHANGES>
if (isFactoryMethod(am)) {
<CHANGEE>
// And must take one of expected arg types (or supertype)
Class<?> actualArgType = am.getRawParameterType(0);
for (Class<?> expArgType : expArgTypes) {
// And one that matches what we would pass in
if (actualArgType.isAssignableFrom(expArgType)) {
return am.getAnnotated();
}
}
}
}
return null;
}
{
/* First: return<SCANS>, value);
} catch (IllegalAccessException e) {
throw new IllegalArgumentException("Failed to setValue() with method "
+getFullName()+": "+e.getMessage(), e);
} catch (InvocationTargetException e) {
throw new IllegalArgumentException("Failed to setValue() with method "
+getFullName()+": "+e.getMessage(), e);
}
}
@Override
public Object getValue(Object pojo) throws IllegalArgumentException
{
try {
return _method.invoke(pojo);
} catch (IllegalAccessException e) {
throw new IllegalArgumentException("Failed to getValue() with method "
+getFullName()+": "+e.getMessage(), e);
} catch (InvocationTargetException e) {
throw new IllegalArgumentException("Failed to getValue() with method "
+getFullName()+": "+e.getMessage(), e);
}
}
/*
/*****************************************************
/* Extended API, generic
/*****************************************************
*/
public String getFullName() {
return getDeclaringClass().getName() + "#" + getName() + "("
+getParameterCount()+" params)";
}
public Class<?>[] getRawParameterTypes()
{
if (_paramClasses == null) {
_paramClasses = _method.getParameterTypes();
}
return _paramClasses;
}
@Deprecated // since 2.7
public Type[] getGenericParameterTypes() {
return _method.getGenericParameterTypes();
}
public Class<?> getRawReturnType() {
return _method.getReturnType();
}
/**
* Helper method that can be used to check whether method returns
* a value or not; if return type declared as <code>void</code>, returns
* false, otherwise true
*
* @since 2.4
*/
public boolean hasReturnType() {
Class<?> rt = getRawReturnType();
return (rt != Void.TYPE && rt != Void.class);
}
/*
/********************************************************
/* Other
/********************************************************
*/
@Override
public String toString() {
return "[method "+getFullName()+"]";
}
@Override
public int hashCode() {
return _method.getName().hashCode();
}
@Override
public boolean equals(Object o) {
if (o == this) return true;
if (o == null || o.getClass() != getClass()) return false;
return ((AnnotatedMethod) o)._method == _method;
JacksonDatabind, 65
<FILEB>
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: (%s) %s",
re.getClass().getName(), re.getMessage());
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
if (isFactoryMethod(am) && am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
if (am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
} else {
return null;
}
return new StdKeyDeserializer(kind, raw);
}
@Override
public Object deserializeKey(String key, DeserializationContext ctxt)
throws IOException
{
if (key == null) { // is this even legal call?
return null;
}
try {
Object result = _parse(key, ctxt);
if (result != null) {
return result;
}
} catch (Exception re) {
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: %s", re.getMessage());
<CHANGEE>
}
if (_keyClass.isEnum() && ctxt.getConfig().isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
return null;
}
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation");
}
public Class<?> getKeyClass() { return _keyClass; }
protected Object _parse(String key, DeserializationContext ctxt) throws Exception
{
switch (_kind) {
case TYPE_BOOLEAN:
if ("true".equals(key)) {
<FILEE>
<FILEB>
*/
if (ac.getParameterCount() == 1) {
Class<?> actArg = ac.getRawParameterType(0);
for (Class<?> expArg : argTypes) {
if (expArg == actArg) {
return ac.getAnnotated();
}
}
}
}
return null;
}
@Override
public Method findFactoryMethod(Class<?>... expArgTypes)
{
// So, of all single-arg static methods:
for (AnnotatedMethod am : _classInfo.getStaticMethods()) {
// 24-Oct-2016, tatu: Better ensure it only takes 1 arg, no matter what
<CHANGES>
if (isFactoryMethod(am)) {
<CHANGEE>
// And must take one of expected arg types (or supertype)
Class<?> actualArgType = am.getRawParameterType(0);
for (Class<?> expArgType : expArgTypes) {
// And one that matches what we would pass in
if (actualArgType.isAssignableFrom(expArgType)) {
return am.getAnnotated();
}
}
}
}
return null;
}
{
/* First: return<SCANS> references,
* not instances
*/
protected final static HashMap<String, Class<? extends JsonSerializer<?>>> _concreteLazy;
static {
HashMap<String, Class<? extends JsonSerializer<?>>> concLazy
= new HashMap<String, Class<? extends JsonSerializer<?>>>();
HashMap<String, JsonSerializer<?>> concrete
= new HashMap<String, JsonSerializer<?>>();
/* String and string-like types (note: date types explicitly
* not included -- can use either textual or numeric serialization)
*/
concrete.put(String.class.getName(), new StringSerializer());
final ToStringSerializer sls = ToStringSerializer.instance;
concrete.put(StringBuffer.class.getName(), sls);
concrete.put(StringBuilder.class.getName(), sls);
concrete.put(Character.class.getName(), sls);
concrete.put(Character.TYPE.getName(), sls);
// Primitives/wrappers for primitives (primitives needed for Beans)
NumberSerializers.addAll(concrete);
concrete.put(Boolean.TYPE.getName(), new BooleanSerializer(true));
concrete.put(Boolean.class.getName(), new BooleanSerializer(false));
// Other numbers, more complicated
concrete.put(BigInteger.class.getName(), new NumberSerializer(BigInteger.class));
concrete.put(BigDecimal.class.getName(),new NumberSerializer(BigDecimal.class));
// Other discrete non-container types:
// First, Date/Time zoo:
concrete.put(Calendar.class.getName(), CalendarSerializer.instance);
concrete.put(java.util.Date.class.getName(), DateSerializer.instance);
// And then other standard non-structured JDK types
for (Map.Entry<Class<?>,Object> en : StdJdkSerializers.all()) {
Object value = en.getValue();
if (value instanceof JsonSerializer<?>) {
concrete.put(en.getKey().getName(), (JsonSerializer<?>) value);
} else if (value instanceof Class<?>) {
@SuppressWarnings("unchecked")
Class<? extends JsonSerializer<?>> cls = (Class<? extends JsonSerializer<?>>) value;
concLazy.put(en.getKey().getName(), cls);
} else { // should never happen, but:
throw new IllegalStateException("Internal error: unrecognized value of type "+en.getClass().getName());
}
}
// Jackson-specific type(s)
// (
JacksonDatabind, 65
<FILEB>
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: (%s) %s",
re.getClass().getName(), re.getMessage());
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
if (isFactoryMethod(am) && am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
if (am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
} else {
return null;
}
return new StdKeyDeserializer(kind, raw);
}
@Override
public Object deserializeKey(String key, DeserializationContext ctxt)
throws IOException
{
if (key == null) { // is this even legal call?
return null;
}
try {
Object result = _parse(key, ctxt);
if (result != null) {
return result;
}
} catch (Exception re) {
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: %s", re.getMessage());
<CHANGEE>
}
if (_keyClass.isEnum() && ctxt.getConfig().isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
return null;
}
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation");
}
public Class<?> getKeyClass() { return _keyClass; }
protected Object _parse(String key, DeserializationContext ctxt) throws Exception
{
switch (_kind) {
case TYPE_BOOLEAN:
if ("true".equals(key)) {
<FILEE>
<FILEB>
*/
if (ac.getParameterCount() == 1) {
Class<?> actArg = ac.getRawParameterType(0);
for (Class<?> expArg : argTypes) {
if (expArg == actArg) {
return ac.getAnnotated();
}
}
}
}
return null;
}
@Override
public Method findFactoryMethod(Class<?>... expArgTypes)
{
// So, of all single-arg static methods:
for (AnnotatedMethod am : _classInfo.getStaticMethods()) {
// 24-Oct-2016, tatu: Better ensure it only takes 1 arg, no matter what
<CHANGES>
if (isFactoryMethod(am)) {
<CHANGEE>
// And must take one of expected arg types (or supertype)
Class<?> actualArgType = am.getRawParameterType(0);
for (Class<?> expArgType : expArgTypes) {
// And one that matches what we would pass in
if (actualArgType.isAssignableFrom(expArgType)) {
return am.getAnnotated();
}
}
}
}
return null;
}
{
/* First: return<SCANS>getAnnotationIntrospector().findFilterId((Annotated)beanDesc.getClassInfo());
}
/**
* Helper method to check whether global settings and/or class
* annotations for the bean class indicate that static typing
* (declared types) should be used for properties.
* (instead of dynamic runtime types).
*
* @since 2.1 (earlier had variant with additional 'property' parameter)
*/
protected boolean usesStaticTyping(SerializationConfig config,
BeanDescription beanDesc, TypeSerializer typeSer)
{
/* 16-Aug-2010, tatu: If there is a (value) type serializer, we can not force
* static typing; that would make it impossible to handle expected subtypes
*/
if (typeSer != null) {
return false;
}
AnnotationIntrospector intr = config.getAnnotationIntrospector();
JsonSerialize.Typing t = intr.findSerializationTyping(beanDesc.getClassInfo());
if (t != null && t != JsonSerialize.Typing.DEFAULT_TYPING) {
return (t == JsonSerialize.Typing.STATIC);
}
return config.isEnabled(MapperFeature.USE_STATIC_TYPING);
}
protected Class<?> _verifyAsClass(Object src, String methodName, Class<?> noneClass)
{
if (src == null) {
return null;
}
if (!(src instanceof Class)) {
throw new IllegalStateException("AnnotationIntrospector."+methodName+"() returned value of type "+src.getClass().getName()+": expected type JsonSerializer or Class<JsonSerializer> instead");
}
Class<?> cls = (Class<?>) src;
if (cls == noneClass || ClassUtil.isBogusClass(cls)) {
return null;
}
return cls;
}
}
JacksonDatabind, 65
<FILEB>
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: (%s) %s",
re.getClass().getName(), re.getMessage());
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
if (isFactoryMethod(am) && am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
if (am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
} else {
return null;
}
return new StdKeyDeserializer(kind, raw);
}
@Override
public Object deserializeKey(String key, DeserializationContext ctxt)
throws IOException
{
if (key == null) { // is this even legal call?
return null;
}
try {
Object result = _parse(key, ctxt);
if (result != null) {
return result;
}
} catch (Exception re) {
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: %s", re.getMessage());
<CHANGEE>
}
if (_keyClass.isEnum() && ctxt.getConfig().isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
return null;
}
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation");
}
public Class<?> getKeyClass() { return _keyClass; }
protected Object _parse(String key, DeserializationContext ctxt) throws Exception
{
switch (_kind) {
case TYPE_BOOLEAN:
if ("true".equals(key)) {
<FILEE>
<FILEB>
*/
if (ac.getParameterCount() == 1) {
Class<?> actArg = ac.getRawParameterType(0);
for (Class<?> expArg : argTypes) {
if (expArg == actArg) {
return ac.getAnnotated();
}
}
}
}
return null;
}
@Override
public Method findFactoryMethod(Class<?>... expArgTypes)
{
// So, of all single-arg static methods:
for (AnnotatedMethod am : _classInfo.getStaticMethods()) {
// 24-Oct-2016, tatu: Better ensure it only takes 1 arg, no matter what
<CHANGES>
if (isFactoryMethod(am)) {
<CHANGEE>
// And must take one of expected arg types (or supertype)
Class<?> actualArgType = am.getRawParameterType(0);
for (Class<?> expArgType : expArgTypes) {
// And one that matches what we would pass in
if (actualArgType.isAssignableFrom(expArgType)) {
return am.getAnnotated();
}
}
}
}
return null;
}
{
/* First: return<SCANS> {
String str = "DateFormat "+getClass().getName();
TimeZone tz = _timezone;
if (tz != null) {
str += " (timezone: "+tz+")";
}
str += "(locale: "+_locale+")";
return str;
}
@Override // since 2.7[.2], as per [databind#1130]
public boolean equals(Object o) {
return (o == this);
}
@Override // since 2.7[.2], as per [databind#1130]
public int hashCode() {
return System.identityHashCode(this);
}
/*
/**********************************************************
/* Helper methods
/**********************************************************
*/
/**
* Overridable helper method used to figure out which of supported
* formats is the likeliest match.
*/
protected boolean looksLikeISO8601(String dateStr)
{
if (dateStr.length() >= 5
&& Character.isDigit(dateStr.charAt(0))
&& Character.isDigit(dateStr.charAt(3))
&& dateStr.charAt(4) == '-'
) {
return true;
}
return false;
}
protected Date parseAsISO8601(String dateStr, ParsePosition pos, boolean throwErrors)
throws ParseException
{
/* 21-May-2009, tatu: DateFormat has very strict handling of
* timezone modifiers for ISO-8601. So we need to do some scrubbing.
*/
/* First: do we have "zulu" format ('Z' == "UTC")? If yes, that's
* quite simple because we already set date format timezone to be
* UTC, and hence can just strip out 'Z' altogether
*/
int len = dateStr.length();
char c = dateStr.charAt(len-1);
DateFormat df;
String formatStr;
// Need to support "plain" date...
if (len <= 10 && Character.isDigit(c)) {
df = _formatPlain;
formatStr = DATE_FORMAT_STR_PLAIN;
if (df == null) {
df = _formatPlain = _cloneFormat(DATE_FORMAT_PLAIN, formatStr,
_timezone, _locale,
JacksonDatabind, 65
<FILEB>
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: (%s) %s",
re.getClass().getName(), re.getMessage());
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
if (isFactoryMethod(am) && am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
if (am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
} else {
return null;
}
return new StdKeyDeserializer(kind, raw);
}
@Override
public Object deserializeKey(String key, DeserializationContext ctxt)
throws IOException
{
if (key == null) { // is this even legal call?
return null;
}
try {
Object result = _parse(key, ctxt);
if (result != null) {
return result;
}
} catch (Exception re) {
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: %s", re.getMessage());
<CHANGEE>
}
if (_keyClass.isEnum() && ctxt.getConfig().isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
return null;
}
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation");
}
public Class<?> getKeyClass() { return _keyClass; }
protected Object _parse(String key, DeserializationContext ctxt) throws Exception
{
switch (_kind) {
case TYPE_BOOLEAN:
if ("true".equals(key)) {
<FILEE>
<FILEB>
*/
if (ac.getParameterCount() == 1) {
Class<?> actArg = ac.getRawParameterType(0);
for (Class<?> expArg : argTypes) {
if (expArg == actArg) {
return ac.getAnnotated();
}
}
}
}
return null;
}
@Override
public Method findFactoryMethod(Class<?>... expArgTypes)
{
// So, of all single-arg static methods:
for (AnnotatedMethod am : _classInfo.getStaticMethods()) {
// 24-Oct-2016, tatu: Better ensure it only takes 1 arg, no matter what
<CHANGES>
if (isFactoryMethod(am)) {
<CHANGEE>
// And must take one of expected arg types (or supertype)
Class<?> actualArgType = am.getRawParameterType(0);
for (Class<?> expArgType : expArgTypes) {
// And one that matches what we would pass in
if (actualArgType.isAssignableFrom(expArgType)) {
return am.getAnnotated();
}
}
}
}
return null;
}
{
/* First: return<SCANS>] != null;
}
/**
* @since 2.6
*/
public boolean hasPropertyBasedCreator() {
return _creators[C_PROPS] != null;
}
/*
* /********************************************************** /* Helper
* methods /**********************************************************
*/
private JavaType _computeDelegateType(AnnotatedWithParams creator,
SettableBeanProperty[] delegateArgs) {
if (!_hasNonDefaultCreator || (creator == null)) {
return null;
}
// need to find type...
int ix = 0;
if (delegateArgs != null) {
for (int i = 0, len = delegateArgs.length; i < len; ++i) {
if (delegateArgs[i] == null) { // marker for delegate itself
ix = i;
break;
}
}
}
return creator.getParameterType(ix);
}
private <T extends AnnotatedMember> T _fixAccess(T member) {
if (member != null && _canFixAccess) {
ClassUtil.checkAndFixAccess((Member) member.getAnnotated(),
_forceAccess);
}
return member;
}
protected void verifyNonDup(AnnotatedWithParams newOne, int typeIndex,
boolean explicit) {
final int mask = (1 << typeIndex);
_hasNonDefaultCreator = true;
AnnotatedWithParams oldOne = _creators[typeIndex];
// already had an explicitly marked one?
if (oldOne != null) {
boolean verify;
if ((_explicitCreators & mask) != 0) { // already had explicitly
// annotated, leave as-is
// but skip, if new one not annotated
if (!explicit) {
return;
}
// both explicit: verify
verify = true;
} else {
// otherwise only verify if neither explicitly annotated.
verify = !explicit;
}
// one more thing: ok to override in sub-class
if (verify && (oldOne.getClass() == newOne.getClass())) {
// [databind#667]: avoid one particular class of bogus problems
Class<?> oldType = oldOne.getRawParameterType(0);
Class<?> newType = newOne.getRawParameterType(0);
if (oldType == newType) {
// 13-Jul-201
JacksonDatabind, 65
<FILEB>
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: (%s) %s",
re.getClass().getName(), re.getMessage());
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
if (isFactoryMethod(am) && am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
if (am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
} else {
return null;
}
return new StdKeyDeserializer(kind, raw);
}
@Override
public Object deserializeKey(String key, DeserializationContext ctxt)
throws IOException
{
if (key == null) { // is this even legal call?
return null;
}
try {
Object result = _parse(key, ctxt);
if (result != null) {
return result;
}
} catch (Exception re) {
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: %s", re.getMessage());
<CHANGEE>
}
if (_keyClass.isEnum() && ctxt.getConfig().isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
return null;
}
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation");
}
public Class<?> getKeyClass() { return _keyClass; }
protected Object _parse(String key, DeserializationContext ctxt) throws Exception
{
switch (_kind) {
case TYPE_BOOLEAN:
if ("true".equals(key)) {
<FILEE>
<FILEB>
*/
if (ac.getParameterCount() == 1) {
Class<?> actArg = ac.getRawParameterType(0);
for (Class<?> expArg : argTypes) {
if (expArg == actArg) {
return ac.getAnnotated();
}
}
}
}
return null;
}
@Override
public Method findFactoryMethod(Class<?>... expArgTypes)
{
// So, of all single-arg static methods:
for (AnnotatedMethod am : _classInfo.getStaticMethods()) {
// 24-Oct-2016, tatu: Better ensure it only takes 1 arg, no matter what
<CHANGES>
if (isFactoryMethod(am)) {
<CHANGEE>
// And must take one of expected arg types (or supertype)
Class<?> actualArgType = am.getRawParameterType(0);
for (Class<?> expArgType : expArgTypes) {
// And one that matches what we would pass in
if (actualArgType.isAssignableFrom(expArgType)) {
return am.getAnnotated();
}
}
}
}
return null;
}
{
/* First: return<SCANS> Accessor that may be used to get lazily-constructed efficient
* representation of the simple name.
*
* @since 2.4
*/
public SerializableString simpleAsEncoded(MapperConfig<?> config) {
SerializableString sstr = _encodedSimple;
if (sstr == null) {
if (config == null) {
sstr = new SerializedString(_simpleName);
} else {
sstr = config.compileString(_simpleName);
}
_encodedSimple = sstr;
}
return sstr;
}
public String getNamespace() {
return _namespace;
}
public boolean hasSimpleName() {
return _simpleName.length() > 0;
}
/**
* @since 2.3
*/
public boolean hasSimpleName(String str) {
if (str == null) {
return _simpleName == null;
}
return str.equals(_simpleName);
}
public boolean hasNamespace() {
return _namespace != null;
}
/**
* Method that is basically equivalent of:
*<pre>
* !hasSimpleName() << !hasNamespace();
*</pre>
*
* @since 2.4
*/
public boolean isEmpty() {
return (_namespace == null) && (_simpleName.isEmpty());
}
/*
/**********************************************************
/* Std method overrides
/**********************************************************
*/
@Override
public boolean equals(Object o)
{
if (o == this) return true;
if (o == null) return false;
/* 13-Nov-2012, tatu: by default, require strict type equality.
* Re-evaluate if this becomes an issue.
*/
if (o.getClass() != getClass()) return false;
// 13-Nov-2012, tatu: Should we have specific rules on matching USE_DEFAULT?
// (like, it only ever matching exact instance)
// If we did, would need to check symmetrically; that is, if either 'this'
// or 'o' was USE_DEFAULT, both would have to be.
PropertyName other = (PropertyName) o;
if (_simpleName == null) {
if (other._simpleName != null) return false
JacksonDatabind, 65
<FILEB>
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: (%s) %s",
re.getClass().getName(), re.getMessage());
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
if (isFactoryMethod(am) && am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
if (am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
} else {
return null;
}
return new StdKeyDeserializer(kind, raw);
}
@Override
public Object deserializeKey(String key, DeserializationContext ctxt)
throws IOException
{
if (key == null) { // is this even legal call?
return null;
}
try {
Object result = _parse(key, ctxt);
if (result != null) {
return result;
}
} catch (Exception re) {
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: %s", re.getMessage());
<CHANGEE>
}
if (_keyClass.isEnum() && ctxt.getConfig().isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
return null;
}
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation");
}
public Class<?> getKeyClass() { return _keyClass; }
protected Object _parse(String key, DeserializationContext ctxt) throws Exception
{
switch (_kind) {
case TYPE_BOOLEAN:
if ("true".equals(key)) {
<FILEE>
<FILEB>
*/
if (ac.getParameterCount() == 1) {
Class<?> actArg = ac.getRawParameterType(0);
for (Class<?> expArg : argTypes) {
if (expArg == actArg) {
return ac.getAnnotated();
}
}
}
}
return null;
}
@Override
public Method findFactoryMethod(Class<?>... expArgTypes)
{
// So, of all single-arg static methods:
for (AnnotatedMethod am : _classInfo.getStaticMethods()) {
// 24-Oct-2016, tatu: Better ensure it only takes 1 arg, no matter what
<CHANGES>
if (isFactoryMethod(am)) {
<CHANGEE>
// And must take one of expected arg types (or supertype)
Class<?> actualArgType = am.getRawParameterType(0);
for (Class<?> expArgType : expArgTypes) {
// And one that matches what we would pass in
if (actualArgType.isAssignableFrom(expArgType)) {
return am.getAnnotated();
}
}
}
}
return null;
}
{
/* First: return<SCANS>since 2.4.6
*/
private boolean _hasCustomValueHandler(JavaType t) {
if (t.isContainerType()) {
JavaType ct = t.getContentType();
if (ct != null) {
return (ct.getValueHandler() != null) || (ct.getTypeHandler() != null);
}
}
return false;
}
private Class<?> _verifyAsClass(Object src, String methodName, Class<?> noneClass)
{
if (src == null) {
return null;
}
if (!(src instanceof Class)) {
throw new IllegalStateException("AnnotationIntrospector."+methodName+"() returned value of type "+src.getClass().getName()+": expected type JsonSerializer or Class<JsonSerializer> instead");
}
Class<?> cls = (Class<?>) src;
if (cls == noneClass || ClassUtil.isBogusClass(cls)) {
return null;
}
return cls;
}
/*
/**********************************************************
/* Overridable error reporting methods
/**********************************************************
*/
// NOTE: changed 2.6 -> 2.7 to pass context; no way to make backwards compatible
protected JsonDeserializer<Object> _handleUnknownValueDeserializer(DeserializationContext ctxt, JavaType type)
throws JsonMappingException
{
/* Let's try to figure out the reason, to give better error
* messages
*/
Class<?> rawClass = type.getRawClass();
if (!ClassUtil.isConcrete(rawClass)) {
ctxt.reportMappingException("Can not find a Value deserializer for abstract type %s", type);
}
ctxt.reportMappingException("Can not find a Value deserializer for type %s", type);
return null;
}
protected KeyDeserializer _handleUnknownKeyDeserializer(DeserializationContext ctxt, JavaType type)
throws JsonMappingException
{
ctxt.reportMappingException("Can not find a (Map) Key deserializer for type %s", type);
return null;
}
}
JacksonDatabind, 65
<FILEB>
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: (%s) %s",
re.getClass().getName(), re.getMessage());
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
if (isFactoryMethod(am) && am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
if (am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
} else {
return null;
}
return new StdKeyDeserializer(kind, raw);
}
@Override
public Object deserializeKey(String key, DeserializationContext ctxt)
throws IOException
{
if (key == null) { // is this even legal call?
return null;
}
try {
Object result = _parse(key, ctxt);
if (result != null) {
return result;
}
} catch (Exception re) {
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: %s", re.getMessage());
<CHANGEE>
}
if (_keyClass.isEnum() && ctxt.getConfig().isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
return null;
}
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation");
}
public Class<?> getKeyClass() { return _keyClass; }
protected Object _parse(String key, DeserializationContext ctxt) throws Exception
{
switch (_kind) {
case TYPE_BOOLEAN:
if ("true".equals(key)) {
<FILEE>
<FILEB>
*/
if (ac.getParameterCount() == 1) {
Class<?> actArg = ac.getRawParameterType(0);
for (Class<?> expArg : argTypes) {
if (expArg == actArg) {
return ac.getAnnotated();
}
}
}
}
return null;
}
@Override
public Method findFactoryMethod(Class<?>... expArgTypes)
{
// So, of all single-arg static methods:
for (AnnotatedMethod am : _classInfo.getStaticMethods()) {
// 24-Oct-2016, tatu: Better ensure it only takes 1 arg, no matter what
<CHANGES>
if (isFactoryMethod(am)) {
<CHANGEE>
// And must take one of expected arg types (or supertype)
Class<?> actualArgType = am.getRawParameterType(0);
for (Class<?> expArgType : expArgTypes) {
// And one that matches what we would pass in
if (actualArgType.isAssignableFrom(expArgType)) {
return am.getAnnotated();
}
}
}
}
return null;
}
{
/* First: return<SCANS>("unchecked")
public StdDelegatingSerializer(Converter<Object,?> converter,
JavaType delegateType, JsonSerializer<?> delegateSerializer)
{
super(delegateType);
_converter = converter;
_delegateType = delegateType;
_delegateSerializer = (JsonSerializer<Object>) delegateSerializer;
}
/**
* Method used for creating resolved contextual instances. Must be
* overridden when sub-classing.
*/
protected StdDelegatingSerializer withDelegate(Converter<Object,?> converter,
JavaType delegateType, JsonSerializer<?> delegateSerializer)
{
if (getClass() != StdDelegatingSerializer.class) {
throw new IllegalStateException("Sub-class "+getClass().getName()+" must override 'withDelegate'");
}
return new StdDelegatingSerializer(converter, delegateType, delegateSerializer);
}
/*
/**********************************************************
/* Contextualization
/**********************************************************
*/
@Override
public void resolve(SerializerProvider provider) throws JsonMappingException
{
if ((_delegateSerializer != null)
&& (_delegateSerializer instanceof ResolvableSerializer)) {
((ResolvableSerializer) _delegateSerializer).resolve(provider);
}
}
@Override
public JsonSerializer<?> createContextual(SerializerProvider provider, BeanProperty property)
throws JsonMappingException
{
JsonSerializer<?> delSer = _delegateSerializer;
JavaType delegateType = _delegateType;
if (delSer == null) {
// Otherwise, need to locate serializer to delegate to. For that we need type information...
if (delegateType == null) {
delegateType = _converter.getOutputType(provider.getTypeFactory());
}
/* 02-Apr-2015, tatu: For "dynamic case", where type is only specified as
* java.lang.Object (or missing generic), [databind#731]
*/
if (!delegateType.isJavaLangObject()) {
delSer = provider.findValueSerializer(delegateType);
}
}
if (delSer instanceof ContextualSerializer) {
delSer = provider.handleSecondaryContextualization(delSer, property);
}
if (delSer == _delegateSerializer && delegateType == _delegateType) {
return this;
}
return withDelegate(_converter, delegateType, delSer);
}
/*
/**********************************************************
/* Accessors
/**********************************************************
*/
protected Converter<
JacksonDatabind, 65
<FILEB>
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: (%s) %s",
re.getClass().getName(), re.getMessage());
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
if (isFactoryMethod(am) && am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
if (am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
} else {
return null;
}
return new StdKeyDeserializer(kind, raw);
}
@Override
public Object deserializeKey(String key, DeserializationContext ctxt)
throws IOException
{
if (key == null) { // is this even legal call?
return null;
}
try {
Object result = _parse(key, ctxt);
if (result != null) {
return result;
}
} catch (Exception re) {
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: %s", re.getMessage());
<CHANGEE>
}
if (_keyClass.isEnum() && ctxt.getConfig().isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
return null;
}
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation");
}
public Class<?> getKeyClass() { return _keyClass; }
protected Object _parse(String key, DeserializationContext ctxt) throws Exception
{
switch (_kind) {
case TYPE_BOOLEAN:
if ("true".equals(key)) {
<FILEE>
<FILEB>
*/
if (ac.getParameterCount() == 1) {
Class<?> actArg = ac.getRawParameterType(0);
for (Class<?> expArg : argTypes) {
if (expArg == actArg) {
return ac.getAnnotated();
}
}
}
}
return null;
}
@Override
public Method findFactoryMethod(Class<?>... expArgTypes)
{
// So, of all single-arg static methods:
for (AnnotatedMethod am : _classInfo.getStaticMethods()) {
// 24-Oct-2016, tatu: Better ensure it only takes 1 arg, no matter what
<CHANGES>
if (isFactoryMethod(am)) {
<CHANGEE>
// And must take one of expected arg types (or supertype)
Class<?> actualArgType = am.getRawParameterType(0);
for (Class<?> expArgType : expArgTypes) {
// And one that matches what we would pass in
if (actualArgType.isAssignableFrom(expArgType)) {
return am.getAnnotated();
}
}
}
}
return null;
}
{
/* First: return<SCANS> @Override
public JsonNode getSchema(SerializerProvider provider, Type typeHint,
boolean isOptional) throws JsonMappingException
{
if (_delegateSerializer instanceof SchemaAware) {
return ((SchemaAware) _delegateSerializer).getSchema(provider, typeHint, isOptional);
}
return super.getSchema(provider, typeHint);
}
@Override
public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType typeHint)
throws JsonMappingException
{
/* 03-Sep-2012, tatu: Not sure if this can be made to really work
* properly... but for now, try this:
*/
// 02-Apr-2015, tatu: For dynamic case, very little we can do
if (_delegateSerializer != null) {
_delegateSerializer.acceptJsonFormatVisitor(visitor, typeHint);
}
}
/*
/**********************************************************
/* Overridable methods
/**********************************************************
*/
/**
* Method called to convert from source Java value into delegate
* value (which will be serialized using standard Jackson serializer for delegate type)
*<P>
* The default implementation uses configured {@link Converter} to do
* conversion.
*
* @param value Value to convert
*
* @return Result of conversion
*/
protected Object convertValue(Object value) {
return _converter.convert(value);
}
/**
* Helper method used for locating serializer to use in dynamic use case, where
* actual type value gets converted to is not specified beyond basic
* {@link java.lang.Object}, and where serializer needs to be located dynamically
* based on actual value type.
*
* @since 2.6
*/
protected JsonSerializer<Object> _findSerializer(Object value, SerializerProvider serializers)
throws JsonMappingException
{
// NOTE: will NOT call contextualization
return serializers.findValueSerializer(value.getClass());
}
}
JacksonDatabind, 65
<FILEB>
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: (%s) %s",
re.getClass().getName(), re.getMessage());
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
if (isFactoryMethod(am) && am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
if (am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
} else {
return null;
}
return new StdKeyDeserializer(kind, raw);
}
@Override
public Object deserializeKey(String key, DeserializationContext ctxt)
throws IOException
{
if (key == null) { // is this even legal call?
return null;
}
try {
Object result = _parse(key, ctxt);
if (result != null) {
return result;
}
} catch (Exception re) {
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: %s", re.getMessage());
<CHANGEE>
}
if (_keyClass.isEnum() && ctxt.getConfig().isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
return null;
}
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation");
}
public Class<?> getKeyClass() { return _keyClass; }
protected Object _parse(String key, DeserializationContext ctxt) throws Exception
{
switch (_kind) {
case TYPE_BOOLEAN:
if ("true".equals(key)) {
<FILEE>
<FILEB>
*/
if (ac.getParameterCount() == 1) {
Class<?> actArg = ac.getRawParameterType(0);
for (Class<?> expArg : argTypes) {
if (expArg == actArg) {
return ac.getAnnotated();
}
}
}
}
return null;
}
@Override
public Method findFactoryMethod(Class<?>... expArgTypes)
{
// So, of all single-arg static methods:
for (AnnotatedMethod am : _classInfo.getStaticMethods()) {
// 24-Oct-2016, tatu: Better ensure it only takes 1 arg, no matter what
<CHANGES>
if (isFactoryMethod(am)) {
<CHANGEE>
// And must take one of expected arg types (or supertype)
Class<?> actualArgType = am.getRawParameterType(0);
for (Class<?> expArgType : expArgTypes) {
// And one that matches what we would pass in
if (actualArgType.isAssignableFrom(expArgType)) {
return am.getAnnotated();
}
}
}
}
return null;
}
{
/* First: return<SCANS> value) throws IllegalArgumentException
{
try {
_field.set(pojo, value);
} catch (IllegalAccessException e) {
throw new IllegalArgumentException("Failed to setValue() for field "
+getFullName()+": "+e.getMessage(), e);
}
}
@Override
public Object getValue(Object pojo) throws IllegalArgumentException
{
try {
return _field.get(pojo);
} catch (IllegalAccessException e) {
throw new IllegalArgumentException("Failed to getValue() for field "
+getFullName()+": "+e.getMessage(), e);
}
}
/*
/**********************************************************
/* Extended API, generic
/**********************************************************
*/
public String getFullName() {
return getDeclaringClass().getName() + "#" + getName();
}
public int getAnnotationCount() { return _annotations.size(); }
/**
* @since 2.6
*/
public boolean isTransient() { return Modifier.isTransient(getModifiers()); }
@Override
public int hashCode() {
return _field.getName().hashCode();
}
@Override
public boolean equals(Object o) {
if (o == this) return true;
if (o == null || o.getClass() != getClass()) return false;
return ((AnnotatedField) o)._field == _field;
}
@Override
public String toString() {
return "[field "+getFullName()+"]";
}
/*
/**********************************************************
/* JDK serialization handling
/**********************************************************
*/
Object writeReplace() {
return new AnnotatedField(new Serialization(_field));
}
Object readResolve() {
Class<?> clazz = _serialization.clazz;
try {
Field f = clazz.getDeclaredField(_serialization.name);
// 06-Oct-2012, tatu: Has "lost" its security override, may need to force back
if (!f.isAccessible()) {
ClassUtil.checkAndFixAccess(f, false);
}
return new AnnotatedField(null, f, null);
} catch (Exception e) {
throw new IllegalArgumentException("Could not find method '"+_serialization.name
+"' from Class '"+clazz.getName());
}
}
/**
* Helper class that is used as the workaround to persist
* Field references. It basically just stores declaring class
* and field name.
*/
JacksonDatabind, 65
<FILEB>
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: (%s) %s",
re.getClass().getName(), re.getMessage());
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
if (isFactoryMethod(am) && am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
if (am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
} else {
return null;
}
return new StdKeyDeserializer(kind, raw);
}
@Override
public Object deserializeKey(String key, DeserializationContext ctxt)
throws IOException
{
if (key == null) { // is this even legal call?
return null;
}
try {
Object result = _parse(key, ctxt);
if (result != null) {
return result;
}
} catch (Exception re) {
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: %s", re.getMessage());
<CHANGEE>
}
if (_keyClass.isEnum() && ctxt.getConfig().isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
return null;
}
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation");
}
public Class<?> getKeyClass() { return _keyClass; }
protected Object _parse(String key, DeserializationContext ctxt) throws Exception
{
switch (_kind) {
case TYPE_BOOLEAN:
if ("true".equals(key)) {
<FILEE>
<FILEB>
*/
if (ac.getParameterCount() == 1) {
Class<?> actArg = ac.getRawParameterType(0);
for (Class<?> expArg : argTypes) {
if (expArg == actArg) {
return ac.getAnnotated();
}
}
}
}
return null;
}
@Override
public Method findFactoryMethod(Class<?>... expArgTypes)
{
// So, of all single-arg static methods:
for (AnnotatedMethod am : _classInfo.getStaticMethods()) {
// 24-Oct-2016, tatu: Better ensure it only takes 1 arg, no matter what
<CHANGES>
if (isFactoryMethod(am)) {
<CHANGEE>
// And must take one of expected arg types (or supertype)
Class<?> actualArgType = am.getRawParameterType(0);
for (Class<?> expArgType : expArgTypes) {
// And one that matches what we would pass in
if (actualArgType.isAssignableFrom(expArgType)) {
return am.getAnnotated();
}
}
}
}
return null;
}
{
/* First: return<SCANS> = null;
_filterId = null;
_sortKeys = false;
_suppressableValue = null;
}
/**
* @since 2.5
*/
protected void _ensureOverride() {
if (getClass() != MapSerializer.class) {
throw new IllegalStateException("Missing override in class "+getClass().getName());
}
}
@SuppressWarnings("unchecked")
protected MapSerializer(MapSerializer src, BeanProperty property,
JsonSerializer<?> keySerializer, JsonSerializer<?> valueSerializer,
Set<String> ignoredEntries)
{
super(Map.class, false);
_ignoredEntries = ((ignoredEntries == null) || ignoredEntries.isEmpty())
? null : ignoredEntries;
_keyType = src._keyType;
_valueType = src._valueType;
_valueTypeIsStatic = src._valueTypeIsStatic;
_valueTypeSerializer = src._valueTypeSerializer;
_keySerializer = (JsonSerializer<Object>) keySerializer;
_valueSerializer = (JsonSerializer<Object>) valueSerializer;
_dynamicValueSerializers = src._dynamicValueSerializers;
_property = property;
_filterId = src._filterId;
_sortKeys = src._sortKeys;
_suppressableValue = src._suppressableValue;
}
@Deprecated // since 2.5
protected MapSerializer(MapSerializer src, TypeSerializer vts) {
this(src, vts, src._suppressableValue);
}
/**
* @since 2.5
*/
protected MapSerializer(MapSerializer src, TypeSerializer vts,
Object suppressableValue)
{
super(Map.class, false);
_ignoredEntries = src._ignoredEntries;
_keyType = src._keyType;
_valueType = src._valueType;
_valueTypeIsStatic = src._valueTypeIsStatic;
_valueTypeSerializer = vts;
_keySerializer = src._keySerializer;
_valueSerializer = src._valueSerializer;
_dynamicValueSerializers = src._dynamicValueSerializers;
_property = src._property;
_filterId = src._filterId;
_sortKeys = src._sortKeys;
// 05-Jun-2015, tatu: For referential, this is same as NON_EMPTY; for others, NON_NULL, so:
if (suppressableValue ==
JacksonDatabind, 65
<FILEB>
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: (%s) %s",
re.getClass().getName(), re.getMessage());
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
if (isFactoryMethod(am) && am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
if (am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
} else {
return null;
}
return new StdKeyDeserializer(kind, raw);
}
@Override
public Object deserializeKey(String key, DeserializationContext ctxt)
throws IOException
{
if (key == null) { // is this even legal call?
return null;
}
try {
Object result = _parse(key, ctxt);
if (result != null) {
return result;
}
} catch (Exception re) {
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: %s", re.getMessage());
<CHANGEE>
}
if (_keyClass.isEnum() && ctxt.getConfig().isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
return null;
}
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation");
}
public Class<?> getKeyClass() { return _keyClass; }
protected Object _parse(String key, DeserializationContext ctxt) throws Exception
{
switch (_kind) {
case TYPE_BOOLEAN:
if ("true".equals(key)) {
<FILEE>
<FILEB>
*/
if (ac.getParameterCount() == 1) {
Class<?> actArg = ac.getRawParameterType(0);
for (Class<?> expArg : argTypes) {
if (expArg == actArg) {
return ac.getAnnotated();
}
}
}
}
return null;
}
@Override
public Method findFactoryMethod(Class<?>... expArgTypes)
{
// So, of all single-arg static methods:
for (AnnotatedMethod am : _classInfo.getStaticMethods()) {
// 24-Oct-2016, tatu: Better ensure it only takes 1 arg, no matter what
<CHANGES>
if (isFactoryMethod(am)) {
<CHANGEE>
// And must take one of expected arg types (or supertype)
Class<?> actualArgType = am.getRawParameterType(0);
for (Class<?> expArgType : expArgTypes) {
// And one that matches what we would pass in
if (actualArgType.isAssignableFrom(expArgType)) {
return am.getAnnotated();
}
}
}
}
return null;
}
{
/* First: return<SCANS>Object elemValue : value.values()) {
if ((elemValue != null) && !valueSer.isEmpty(prov, elemValue)) {
return false;
}
}
return true;
}
// But if not statically known, try this:
PropertySerializerMap serializers = _dynamicValueSerializers;
for (Object elemValue : value.values()) {
if (elemValue == null) {
continue;
}
Class<?> cc = elemValue.getClass();
// 05-Nov-2015, tatu: Let's not worry about generic types here, actually;
// unlikely to make any difference, but does add significant overhead
valueSer = serializers.serializerFor(cc);
if (valueSer == null) {
try {
valueSer = _findAndAddDynamic(serializers, cc, prov);
} catch (JsonMappingException e) { // Ugh... can not just throw as-is, so...
// 05-Nov-2015, tatu: For now, probably best not to assume empty then
return false;
}
serializers = _dynamicValueSerializers;
}
if (!valueSer.isEmpty(prov, elemValue)) {
return false;
}
}
return true;
}
@Override
public boolean hasSingleElement(Map<?,?> value) {
return (value.size() == 1);
}
/*
/**********************************************************
/* Extended API
/**********************************************************
*/
/**
* Accessor for currently assigned key serializer. Note that
* this may return null during construction of <code>MapSerializer</code>:
* depedencies are resolved during {@link #createContextual} method
* (which can be overridden by custom implementations), but for some
* dynamic types, it is possible that serializer is only resolved
* during actual serialization.
*
* @since 2.0
*/
public JsonSerializer<?> getKeySerializer() {
return _keySerializer;
}
/*
/**********************************************************
/* JsonSerializer implementation
/**********************************************************
*/
@Override
public void serialize(Map<?,?> value, JsonGenerator gen, SerializerProvider provider)
throws IOException
{
gen.writeStartObject(value);
if (!value.isEmpty()) {
Object suppressableValue = _suppressableValue;
if (suppressableValue ==
JacksonDatabind, 65
<FILEB>
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: (%s) %s",
re.getClass().getName(), re.getMessage());
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
if (isFactoryMethod(am) && am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
if (am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
} else {
return null;
}
return new StdKeyDeserializer(kind, raw);
}
@Override
public Object deserializeKey(String key, DeserializationContext ctxt)
throws IOException
{
if (key == null) { // is this even legal call?
return null;
}
try {
Object result = _parse(key, ctxt);
if (result != null) {
return result;
}
} catch (Exception re) {
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: %s", re.getMessage());
<CHANGEE>
}
if (_keyClass.isEnum() && ctxt.getConfig().isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
return null;
}
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation");
}
public Class<?> getKeyClass() { return _keyClass; }
protected Object _parse(String key, DeserializationContext ctxt) throws Exception
{
switch (_kind) {
case TYPE_BOOLEAN:
if ("true".equals(key)) {
<FILEE>
<FILEB>
*/
if (ac.getParameterCount() == 1) {
Class<?> actArg = ac.getRawParameterType(0);
for (Class<?> expArg : argTypes) {
if (expArg == actArg) {
return ac.getAnnotated();
}
}
}
}
return null;
}
@Override
public Method findFactoryMethod(Class<?>... expArgTypes)
{
// So, of all single-arg static methods:
for (AnnotatedMethod am : _classInfo.getStaticMethods()) {
// 24-Oct-2016, tatu: Better ensure it only takes 1 arg, no matter what
<CHANGES>
if (isFactoryMethod(am)) {
<CHANGEE>
// And must take one of expected arg types (or supertype)
Class<?> actualArgType = am.getRawParameterType(0);
for (Class<?> expArgType : expArgTypes) {
// And one that matches what we would pass in
if (actualArgType.isAssignableFrom(expArgType)) {
return am.getAnnotated();
}
}
}
}
return null;
}
{
/* First: return<SCANS> serializeFieldsUsing(value, gen, provider, _valueSerializer);
} else {
serializeFields(value, gen, provider);
}
}
typeSer.writeTypeSuffixForObject(value, gen);
}
/*
/**********************************************************
/* Secondary serialization methods
/**********************************************************
*/
/**
* General-purpose serialization for contents, where we do not necessarily know
* the value serialization, but
* we do know that no value suppression is needed (which simplifies processing a bit)
*/
public void serializeFields(Map<?,?> value, JsonGenerator gen, SerializerProvider provider)
throws IOException
{
// If value type needs polymorphic type handling, some more work needed:
if (_valueTypeSerializer != null) {
serializeTypedFields(value, gen, provider, null);
return;
}
final JsonSerializer<Object> keySerializer = _keySerializer;
final Set<String> ignored = _ignoredEntries;
PropertySerializerMap serializers = _dynamicValueSerializers;
for (Map.Entry<?,?> entry : value.entrySet()) {
Object valueElem = entry.getValue();
// First, serialize key
Object keyElem = entry.getKey();
if (keyElem == null) {
provider.findNullKeySerializer(_keyType, _property).serialize(null, gen, provider);
} else {
// One twist: is entry ignorable? If so, skip
if ((ignored != null) && ignored.contains(keyElem)) continue;
keySerializer.serialize(keyElem, gen, provider);
}
// And then value
if (valueElem == null) {
provider.defaultSerializeNull(gen);
continue;
}
JsonSerializer<Object> serializer = _valueSerializer;
if (serializer == null) {
Class<?> cc = valueElem.getClass();
serializer = serializers.serializerFor(cc);
if (serializer == null) {
if (_valueType.hasGenericTypes()) {
serializer = _findAndAddDynamic(serializers,
provider.constructSpecializedType(_valueType, cc), provider);
} else {
serializer = _findAndAddDynamic(serializers, cc, provider);
}
serializers = _dynamicValueSerializers;
}
}
try {
serializer.serialize(valueElem, gen, provider);
} catch (Exception e) {
// Add reference information
JacksonDatabind, 65
<FILEB>
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: (%s) %s",
re.getClass().getName(), re.getMessage());
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
if (isFactoryMethod(am) && am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
if (am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
} else {
return null;
}
return new StdKeyDeserializer(kind, raw);
}
@Override
public Object deserializeKey(String key, DeserializationContext ctxt)
throws IOException
{
if (key == null) { // is this even legal call?
return null;
}
try {
Object result = _parse(key, ctxt);
if (result != null) {
return result;
}
} catch (Exception re) {
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: %s", re.getMessage());
<CHANGEE>
}
if (_keyClass.isEnum() && ctxt.getConfig().isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
return null;
}
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation");
}
public Class<?> getKeyClass() { return _keyClass; }
protected Object _parse(String key, DeserializationContext ctxt) throws Exception
{
switch (_kind) {
case TYPE_BOOLEAN:
if ("true".equals(key)) {
<FILEE>
<FILEB>
*/
if (ac.getParameterCount() == 1) {
Class<?> actArg = ac.getRawParameterType(0);
for (Class<?> expArg : argTypes) {
if (expArg == actArg) {
return ac.getAnnotated();
}
}
}
}
return null;
}
@Override
public Method findFactoryMethod(Class<?>... expArgTypes)
{
// So, of all single-arg static methods:
for (AnnotatedMethod am : _classInfo.getStaticMethods()) {
// 24-Oct-2016, tatu: Better ensure it only takes 1 arg, no matter what
<CHANGES>
if (isFactoryMethod(am)) {
<CHANGEE>
// And must take one of expected arg types (or supertype)
Class<?> actualArgType = am.getRawParameterType(0);
for (Class<?> expArgType : expArgTypes) {
// And one that matches what we would pass in
if (actualArgType.isAssignableFrom(expArgType)) {
return am.getAnnotated();
}
}
}
}
return null;
}
{
/* First: return<SCANS> String keyDesc = ""+keyElem;
wrapAndThrow(provider, e, value, keyDesc);
}
}
}
/**
* Serialization method called when exclusion filtering needs to be applied.
*/
public void serializeOptionalFields(Map<?,?> value, JsonGenerator gen, SerializerProvider provider,
Object suppressableValue)
throws IOException
{
// If value type needs polymorphic type handling, some more work needed:
if (_valueTypeSerializer != null) {
serializeTypedFields(value, gen, provider, suppressableValue);
return;
}
final Set<String> ignored = _ignoredEntries;
PropertySerializerMap serializers = _dynamicValueSerializers;
for (Map.Entry<?,?> entry : value.entrySet()) {
// First find key serializer
final Object keyElem = entry.getKey();
JsonSerializer<Object> keySerializer;
if (keyElem == null) {
keySerializer = provider.findNullKeySerializer(_keyType, _property);
} else {
if (ignored != null && ignored.contains(keyElem)) continue;
keySerializer = _keySerializer;
}
// Then value serializer
final Object valueElem = entry.getValue();
JsonSerializer<Object> valueSer;
if (valueElem == null) {
if (suppressableValue != null) { // all suppressions include null-suppression
continue;
}
valueSer = provider.getDefaultNullValueSerializer();
} else {
valueSer = _valueSerializer;
if (valueSer == null) {
Class<?> cc = valueElem.getClass();
valueSer = serializers.serializerFor(cc);
if (valueSer == null) {
if (_valueType.hasGenericTypes()) {
valueSer = _findAndAddDynamic(serializers,
provider.constructSpecializedType(_valueType, cc), provider);
} else {
valueSer = _findAndAddDynamic(serializers, cc, provider);
}
serializers = _dynamicValueSerializers;
}
}
// also may need to skip non-empty values:
if ((suppressableValue == JsonInclude.Include.NON_EMPTY)
&& valueSer.isEmpty(provider, valueElem)) {
continue;
}
}
// and then serialize, if all went well
try {
keySerializer.serialize(keyElem, gen, provider);
valueSer.serialize
JacksonDatabind, 65
<FILEB>
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: (%s) %s",
re.getClass().getName(), re.getMessage());
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
if (isFactoryMethod(am) && am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
if (am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
} else {
return null;
}
return new StdKeyDeserializer(kind, raw);
}
@Override
public Object deserializeKey(String key, DeserializationContext ctxt)
throws IOException
{
if (key == null) { // is this even legal call?
return null;
}
try {
Object result = _parse(key, ctxt);
if (result != null) {
return result;
}
} catch (Exception re) {
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: %s", re.getMessage());
<CHANGEE>
}
if (_keyClass.isEnum() && ctxt.getConfig().isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
return null;
}
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation");
}
public Class<?> getKeyClass() { return _keyClass; }
protected Object _parse(String key, DeserializationContext ctxt) throws Exception
{
switch (_kind) {
case TYPE_BOOLEAN:
if ("true".equals(key)) {
<FILEE>
<FILEB>
*/
if (ac.getParameterCount() == 1) {
Class<?> actArg = ac.getRawParameterType(0);
for (Class<?> expArg : argTypes) {
if (expArg == actArg) {
return ac.getAnnotated();
}
}
}
}
return null;
}
@Override
public Method findFactoryMethod(Class<?>... expArgTypes)
{
// So, of all single-arg static methods:
for (AnnotatedMethod am : _classInfo.getStaticMethods()) {
// 24-Oct-2016, tatu: Better ensure it only takes 1 arg, no matter what
<CHANGES>
if (isFactoryMethod(am)) {
<CHANGEE>
// And must take one of expected arg types (or supertype)
Class<?> actualArgType = am.getRawParameterType(0);
for (Class<?> expArgType : expArgTypes) {
// And one that matches what we would pass in
if (actualArgType.isAssignableFrom(expArgType)) {
return am.getAnnotated();
}
}
}
}
return null;
}
{
/* First: return<SCANS> final Object keyElem = entry.getKey();
if (ignored != null && ignored.contains(keyElem)) continue;
JsonSerializer<Object> keySerializer;
if (keyElem == null) {
keySerializer = provider.findNullKeySerializer(_keyType, _property);
} else {
keySerializer = _keySerializer;
}
// or by value; nulls often suppressed
final Object valueElem = entry.getValue();
JsonSerializer<Object> valueSer;
// And then value
if (valueElem == null) {
if (suppressableValue != null) { // all suppressions include null-suppression
continue;
}
valueSer = provider.getDefaultNullValueSerializer();
} else {
valueSer = _valueSerializer;
if (valueSer == null) {
Class<?> cc = valueElem.getClass();
valueSer = serializers.serializerFor(cc);
if (valueSer == null) {
if (_valueType.hasGenericTypes()) {
valueSer = _findAndAddDynamic(serializers,
provider.constructSpecializedType(_valueType, cc), provider);
} else {
valueSer = _findAndAddDynamic(serializers, cc, provider);
}
serializers = _dynamicValueSerializers;
}
}
// also may need to skip non-empty values:
if ((suppressableValue == JsonInclude.Include.NON_EMPTY)
&& valueSer.isEmpty(provider, valueElem)) {
continue;
}
}
// and with that, ask filter to handle it
prop.reset(keyElem, keySerializer, valueSer);
try {
filter.serializeAsField(valueElem, gen, provider, prop);
} catch (Exception e) {
String keyDesc = ""+keyElem;
wrapAndThrow(provider, e, value, keyDesc);
}
}
}
@Deprecated // since 2.5
public void serializeFilteredFields(Map<?,?> value, JsonGenerator gen, SerializerProvider provider,
PropertyFilter filter) throws IOException {
serializeFilteredFields(value, gen, provider, filter,
provider.isEnabled(SerializationFeature.WRITE_NULL_MAP_VALUES) ? null : JsonInclude.Include.NON_NULL);
}
/**
* @since 2.5
*/
public void serializeTypedFields(Map<?,?> value, JsonGenerator gen
JacksonDatabind, 65
<FILEB>
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: (%s) %s",
re.getClass().getName(), re.getMessage());
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
if (isFactoryMethod(am) && am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
if (am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
} else {
return null;
}
return new StdKeyDeserializer(kind, raw);
}
@Override
public Object deserializeKey(String key, DeserializationContext ctxt)
throws IOException
{
if (key == null) { // is this even legal call?
return null;
}
try {
Object result = _parse(key, ctxt);
if (result != null) {
return result;
}
} catch (Exception re) {
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: %s", re.getMessage());
<CHANGEE>
}
if (_keyClass.isEnum() && ctxt.getConfig().isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
return null;
}
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation");
}
public Class<?> getKeyClass() { return _keyClass; }
protected Object _parse(String key, DeserializationContext ctxt) throws Exception
{
switch (_kind) {
case TYPE_BOOLEAN:
if ("true".equals(key)) {
<FILEE>
<FILEB>
*/
if (ac.getParameterCount() == 1) {
Class<?> actArg = ac.getRawParameterType(0);
for (Class<?> expArg : argTypes) {
if (expArg == actArg) {
return ac.getAnnotated();
}
}
}
}
return null;
}
@Override
public Method findFactoryMethod(Class<?>... expArgTypes)
{
// So, of all single-arg static methods:
for (AnnotatedMethod am : _classInfo.getStaticMethods()) {
// 24-Oct-2016, tatu: Better ensure it only takes 1 arg, no matter what
<CHANGES>
if (isFactoryMethod(am)) {
<CHANGEE>
// And must take one of expected arg types (or supertype)
Class<?> actualArgType = am.getRawParameterType(0);
for (Class<?> expArgType : expArgTypes) {
// And one that matches what we would pass in
if (actualArgType.isAssignableFrom(expArgType)) {
return am.getAnnotated();
}
}
}
}
return null;
}
{
/* First: return<SCANS>, SerializerProvider provider,
Object suppressableValue) // since 2.5
throws IOException
{
final Set<String> ignored = _ignoredEntries;
PropertySerializerMap serializers = _dynamicValueSerializers;
for (Map.Entry<?,?> entry : value.entrySet()) {
Object keyElem = entry.getKey();
JsonSerializer<Object> keySerializer;
if (keyElem == null) {
keySerializer = provider.findNullKeySerializer(_keyType, _property);
} else {
// One twist: is entry ignorable? If so, skip
if (ignored != null && ignored.contains(keyElem)) continue;
keySerializer = _keySerializer;
}
final Object valueElem = entry.getValue();
// And then value
JsonSerializer<Object> valueSer;
if (valueElem == null) {
if (suppressableValue != null) { // all suppression include null suppression
continue;
}
valueSer = provider.getDefaultNullValueSerializer();
} else {
valueSer = _valueSerializer;
Class<?> cc = valueElem.getClass();
valueSer = serializers.serializerFor(cc);
if (valueSer == null) {
if (_valueType.hasGenericTypes()) {
valueSer = _findAndAddDynamic(serializers,
provider.constructSpecializedType(_valueType, cc), provider);
} else {
valueSer = _findAndAddDynamic(serializers, cc, provider);
}
serializers = _dynamicValueSerializers;
}
// also may need to skip non-empty values:
if ((suppressableValue == JsonInclude.Include.NON_EMPTY)
&& valueSer.isEmpty(provider, valueElem)) {
continue;
}
}
keySerializer.serialize(keyElem, gen, provider);
try {
valueSer.serializeWithType(valueElem, gen, provider, _valueTypeSerializer);
} catch (Exception e) {
String keyDesc = ""+keyElem;
wrapAndThrow(provider, e, value, keyDesc);
}
}
}
@Deprecated // since 2.5
protected void serializeTypedFields(Map<?,?> value, JsonGenerator gen, SerializerProvider provider)
throws IOException {
serializeTypedFields(value, gen, provider,
provider.isEnabled(SerializationFeature.WRITE_NULL_MAP_VALUES) ? null : Json
JacksonDatabind, 65
<FILEB>
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: (%s) %s",
re.getClass().getName(), re.getMessage());
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
if (isFactoryMethod(am) && am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
if (am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
} else {
return null;
}
return new StdKeyDeserializer(kind, raw);
}
@Override
public Object deserializeKey(String key, DeserializationContext ctxt)
throws IOException
{
if (key == null) { // is this even legal call?
return null;
}
try {
Object result = _parse(key, ctxt);
if (result != null) {
return result;
}
} catch (Exception re) {
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: %s", re.getMessage());
<CHANGEE>
}
if (_keyClass.isEnum() && ctxt.getConfig().isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
return null;
}
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation");
}
public Class<?> getKeyClass() { return _keyClass; }
protected Object _parse(String key, DeserializationContext ctxt) throws Exception
{
switch (_kind) {
case TYPE_BOOLEAN:
if ("true".equals(key)) {
<FILEE>
<FILEB>
*/
if (ac.getParameterCount() == 1) {
Class<?> actArg = ac.getRawParameterType(0);
for (Class<?> expArg : argTypes) {
if (expArg == actArg) {
return ac.getAnnotated();
}
}
}
}
return null;
}
@Override
public Method findFactoryMethod(Class<?>... expArgTypes)
{
// So, of all single-arg static methods:
for (AnnotatedMethod am : _classInfo.getStaticMethods()) {
// 24-Oct-2016, tatu: Better ensure it only takes 1 arg, no matter what
<CHANGES>
if (isFactoryMethod(am)) {
<CHANGEE>
// And must take one of expected arg types (or supertype)
Class<?> actualArgType = am.getRawParameterType(0);
for (Class<?> expArgType : expArgTypes) {
// And one that matches what we would pass in
if (actualArgType.isAssignableFrom(expArgType)) {
return am.getAnnotated();
}
}
}
}
return null;
}
{
/* First: return<SCANS>) {
return input;
}
// [databind#1411]: TreeMap does not like null key...
if (input.containsKey(null)) {
TreeMap<Object,Object> result = new TreeMap<Object,Object>();
for (Map.Entry<?,?> entry : input.entrySet()) {
Object key = entry.getKey();
if (key == null) {
_writeNullKeyedEntry(gen, provider, suppressableValue, entry.getValue());
continue;
}
result.put(key, entry.getValue());
}
return result;
}
return new TreeMap<Object,Object>(input);
}
protected void _writeNullKeyedEntry(JsonGenerator gen, SerializerProvider provider,
Object suppressableValue, Object value) throws IOException
{
JsonSerializer<Object> keySerializer = provider.findNullKeySerializer(_keyType, _property);
JsonSerializer<Object> valueSer;
if (value == null) {
if (suppressableValue != null) { // all suppressions include null-suppression
return;
}
valueSer = provider.getDefaultNullValueSerializer();
} else {
valueSer = _valueSerializer;
if (valueSer == null) {
Class<?> cc = value.getClass();
valueSer = _dynamicValueSerializers.serializerFor(cc);
if (valueSer == null) {
if (_valueType.hasGenericTypes()) {
valueSer = _findAndAddDynamic(_dynamicValueSerializers,
provider.constructSpecializedType(_valueType, cc), provider);
} else {
valueSer = _findAndAddDynamic(_dynamicValueSerializers, cc, provider);
}
}
}
// also may need to skip non-empty values:
if ((suppressableValue == JsonInclude.Include.NON_EMPTY)
&& valueSer.isEmpty(provider, value)) {
return;
}
}
// and then serialize, if all went well
try {
keySerializer.serialize(null, gen, provider);
valueSer.serialize(value, gen, provider);
} catch (Exception e) {
String keyDesc = "";
wrapAndThrow(provider, e, value, keyDesc);
}
}
}
JacksonDatabind, 65
<FILEB>
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: (%s) %s",
re.getClass().getName(), re.getMessage());
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
if (isFactoryMethod(am) && am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
if (am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
} else {
return null;
}
return new StdKeyDeserializer(kind, raw);
}
@Override
public Object deserializeKey(String key, DeserializationContext ctxt)
throws IOException
{
if (key == null) { // is this even legal call?
return null;
}
try {
Object result = _parse(key, ctxt);
if (result != null) {
return result;
}
} catch (Exception re) {
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: %s", re.getMessage());
<CHANGEE>
}
if (_keyClass.isEnum() && ctxt.getConfig().isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
return null;
}
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation");
}
public Class<?> getKeyClass() { return _keyClass; }
protected Object _parse(String key, DeserializationContext ctxt) throws Exception
{
switch (_kind) {
case TYPE_BOOLEAN:
if ("true".equals(key)) {
<FILEE>
<FILEB>
*/
if (ac.getParameterCount() == 1) {
Class<?> actArg = ac.getRawParameterType(0);
for (Class<?> expArg : argTypes) {
if (expArg == actArg) {
return ac.getAnnotated();
}
}
}
}
return null;
}
@Override
public Method findFactoryMethod(Class<?>... expArgTypes)
{
// So, of all single-arg static methods:
for (AnnotatedMethod am : _classInfo.getStaticMethods()) {
// 24-Oct-2016, tatu: Better ensure it only takes 1 arg, no matter what
<CHANGES>
if (isFactoryMethod(am)) {
<CHANGEE>
// And must take one of expected arg types (or supertype)
Class<?> actualArgType = am.getRawParameterType(0);
for (Class<?> expArgType : expArgTypes) {
// And one that matches what we would pass in
if (actualArgType.isAssignableFrom(expArgType)) {
return am.getAnnotated();
}
}
}
}
return null;
}
{
/* First: return<SCANS>();
}
@Override public int hashCode() { return _hashCode; }
@Override public boolean equals(Object o)
{
if (o == this) return true;
if (o == null || o.getClass() != getClass()) return false;
TypeBindings other = (TypeBindings) o;
int len = _types.length;
if (len != other.size()) {
return false;
}
JavaType[] otherTypes = other._types;
for (int i = 0; i < len; ++i) {
if (!otherTypes[i].equals(_types[i])) {
return false;
}
}
return true;
}
/*
/**********************************************************************
/* Package accessible methods
/**********************************************************************
*/
protected JavaType[] typeParameterArray() {
return _types;
}
/*
/**********************************************************************
/* Helper classes
/**********************************************************************
*/
// 30-Oct-2015, tatu: Surprising, but looks like type parameters access can be bit of
// a hot spot. So avoid for a small number of common generic types. Note that we do
// need both common abstract types and concrete ones; latter for specialization
/**
* Helper class that contains simple logic for avoiding repeated lookups via
* {@link Class#getTypeParameters()} as that can be a performance issue for
* some use cases (wasteful, usually one-off or not reusing mapper).
* Partly isolated to avoid initialization for cases where no generic types are
* used.
*/
static class TypeParamStash {
private final static TypeVariable<?>[] VARS_ABSTRACT_LIST = AbstractList.class.getTypeParameters();
private final static TypeVariable<?>[] VARS_COLLECTION = Collection.class.getTypeParameters();
private final static TypeVariable<?>[] VARS_ITERABLE = Iterable.class.getTypeParameters();
private final static TypeVariable<?>[] VARS_LIST = List.class.getTypeParameters();
private final static TypeVariable<?>[] VARS_ARRAY_LIST = ArrayList.class.getTypeParameters();
private final static TypeVariable<?>[] VARS_MAP = Map.class.getTypeParameters();
private final static TypeVariable<?>[] VARS_HASH_MAP = HashMap.class.getTypeParameters();
private final static TypeVariable<?>[] VARS
JacksonDatabind, 65
<FILEB>
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: (%s) %s",
re.getClass().getName(), re.getMessage());
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
if (isFactoryMethod(am) && am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
if (am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
} else {
return null;
}
return new StdKeyDeserializer(kind, raw);
}
@Override
public Object deserializeKey(String key, DeserializationContext ctxt)
throws IOException
{
if (key == null) { // is this even legal call?
return null;
}
try {
Object result = _parse(key, ctxt);
if (result != null) {
return result;
}
} catch (Exception re) {
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: %s", re.getMessage());
<CHANGEE>
}
if (_keyClass.isEnum() && ctxt.getConfig().isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
return null;
}
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation");
}
public Class<?> getKeyClass() { return _keyClass; }
protected Object _parse(String key, DeserializationContext ctxt) throws Exception
{
switch (_kind) {
case TYPE_BOOLEAN:
if ("true".equals(key)) {
<FILEE>
<FILEB>
*/
if (ac.getParameterCount() == 1) {
Class<?> actArg = ac.getRawParameterType(0);
for (Class<?> expArg : argTypes) {
if (expArg == actArg) {
return ac.getAnnotated();
}
}
}
}
return null;
}
@Override
public Method findFactoryMethod(Class<?>... expArgTypes)
{
// So, of all single-arg static methods:
for (AnnotatedMethod am : _classInfo.getStaticMethods()) {
// 24-Oct-2016, tatu: Better ensure it only takes 1 arg, no matter what
<CHANGES>
if (isFactoryMethod(am)) {
<CHANGEE>
// And must take one of expected arg types (or supertype)
Class<?> actualArgType = am.getRawParameterType(0);
for (Class<?> expArgType : expArgTypes) {
// And one that matches what we would pass in
if (actualArgType.isAssignableFrom(expArgType)) {
return am.getAnnotated();
}
}
}
}
return null;
}
{
/* First: return<SCANS>_LINKED_HASH_MAP = LinkedHashMap.class.getTypeParameters();
public static TypeVariable<?>[] paramsFor1(Class<?> erasedType)
{
if (erasedType == Collection.class) {
return VARS_COLLECTION;
}
if (erasedType == List.class) {
return VARS_LIST;
}
if (erasedType == ArrayList.class) {
return VARS_ARRAY_LIST;
}
if (erasedType == AbstractList.class) {
return VARS_ABSTRACT_LIST;
}
if (erasedType == Iterable.class) {
return VARS_ITERABLE;
}
return erasedType.getTypeParameters();
}
public static TypeVariable<?>[] paramsFor2(Class<?> erasedType)
{
if (erasedType == Map.class) {
return VARS_MAP;
}
if (erasedType == HashMap.class) {
return VARS_HASH_MAP;
}
if (erasedType == LinkedHashMap.class) {
return VARS_LINKED_HASH_MAP;
}
return erasedType.getTypeParameters();
}
}
/**
* Helper type used to allow caching of generic types
*
* @since 2.8
*/
final static class AsKey {
private final Class<?> _raw;
private final JavaType[] _params;
private final int _hash;
public AsKey(Class<?> raw, JavaType[] params, int hash) {
_raw = raw ;
_params = params;
_hash = hash;
}
@Override
public int hashCode() { return _hash; }
@Override
public boolean equals(Object o) {
if (o == this) return true;
if (o == null) return false;
if (o.getClass() != getClass()) return false;
AsKey other = (AsKey) o;
if ((_hash == other._hash) && (_raw == other._raw)) {
final JavaType[] otherParams = other._params;
final int len = _params.length;
if (len == otherParams.length) {
for (int i = 0; i < len; ++i) {
if (!_params[i].equals(otherParams[i])) {
return
JacksonDatabind, 65
<FILEB>
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: (%s) %s",
re.getClass().getName(), re.getMessage());
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
if (isFactoryMethod(am) && am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
if (am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
} else {
return null;
}
return new StdKeyDeserializer(kind, raw);
}
@Override
public Object deserializeKey(String key, DeserializationContext ctxt)
throws IOException
{
if (key == null) { // is this even legal call?
return null;
}
try {
Object result = _parse(key, ctxt);
if (result != null) {
return result;
}
} catch (Exception re) {
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: %s", re.getMessage());
<CHANGEE>
}
if (_keyClass.isEnum() && ctxt.getConfig().isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
return null;
}
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation");
}
public Class<?> getKeyClass() { return _keyClass; }
protected Object _parse(String key, DeserializationContext ctxt) throws Exception
{
switch (_kind) {
case TYPE_BOOLEAN:
if ("true".equals(key)) {
<FILEE>
<FILEB>
*/
if (ac.getParameterCount() == 1) {
Class<?> actArg = ac.getRawParameterType(0);
for (Class<?> expArg : argTypes) {
if (expArg == actArg) {
return ac.getAnnotated();
}
}
}
}
return null;
}
@Override
public Method findFactoryMethod(Class<?>... expArgTypes)
{
// So, of all single-arg static methods:
for (AnnotatedMethod am : _classInfo.getStaticMethods()) {
// 24-Oct-2016, tatu: Better ensure it only takes 1 arg, no matter what
<CHANGES>
if (isFactoryMethod(am)) {
<CHANGEE>
// And must take one of expected arg types (or supertype)
Class<?> actualArgType = am.getRawParameterType(0);
for (Class<?> expArgType : expArgTypes) {
// And one that matches what we would pass in
if (actualArgType.isAssignableFrom(expArgType)) {
return am.getAnnotated();
}
}
}
}
return null;
}
{
/* First: return<SCANS>.TRUE)) {
if (hasSingleElement(value)) {
serializeContents(value, gen, provider);
return;
}
}
gen.writeStartArray();
serializeContents(value, gen, provider);
gen.writeEndArray();
}
@Override
public void serializeContents(Iterable<?> value, JsonGenerator jgen,
SerializerProvider provider) throws IOException
{
Iterator<?> it = value.iterator();
if (it.hasNext()) {
final TypeSerializer typeSer = _valueTypeSerializer;
JsonSerializer<Object> prevSerializer = null;
Class<?> prevClass = null;
do {
Object elem = it.next();
if (elem == null) {
provider.defaultSerializeNull(jgen);
continue;
}
JsonSerializer<Object> currSerializer = _elementSerializer;
if (currSerializer == null) {
// Minor optimization to avoid most lookups:
Class<?> cc = elem.getClass();
if (cc == prevClass) {
currSerializer = prevSerializer;
} else {
currSerializer = provider.findValueSerializer(cc, _property);
prevSerializer = currSerializer;
prevClass = cc;
}
}
if (typeSer == null) {
currSerializer.serialize(elem, jgen, provider);
} else {
currSerializer.serializeWithType(elem, jgen, provider, typeSer);
}
} while (it.hasNext());
}
}
}
JacksonDatabind, 65
<FILEB>
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: (%s) %s",
re.getClass().getName(), re.getMessage());
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
if (isFactoryMethod(am) && am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
if (am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
} else {
return null;
}
return new StdKeyDeserializer(kind, raw);
}
@Override
public Object deserializeKey(String key, DeserializationContext ctxt)
throws IOException
{
if (key == null) { // is this even legal call?
return null;
}
try {
Object result = _parse(key, ctxt);
if (result != null) {
return result;
}
} catch (Exception re) {
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: %s", re.getMessage());
<CHANGEE>
}
if (_keyClass.isEnum() && ctxt.getConfig().isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
return null;
}
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation");
}
public Class<?> getKeyClass() { return _keyClass; }
protected Object _parse(String key, DeserializationContext ctxt) throws Exception
{
switch (_kind) {
case TYPE_BOOLEAN:
if ("true".equals(key)) {
<FILEE>
<FILEB>
*/
if (ac.getParameterCount() == 1) {
Class<?> actArg = ac.getRawParameterType(0);
for (Class<?> expArg : argTypes) {
if (expArg == actArg) {
return ac.getAnnotated();
}
}
}
}
return null;
}
@Override
public Method findFactoryMethod(Class<?>... expArgTypes)
{
// So, of all single-arg static methods:
for (AnnotatedMethod am : _classInfo.getStaticMethods()) {
// 24-Oct-2016, tatu: Better ensure it only takes 1 arg, no matter what
<CHANGES>
if (isFactoryMethod(am)) {
<CHANGEE>
// And must take one of expected arg types (or supertype)
Class<?> actualArgType = am.getRawParameterType(0);
for (Class<?> expArgType : expArgTypes) {
// And one that matches what we would pass in
if (actualArgType.isAssignableFrom(expArgType)) {
return am.getAnnotated();
}
}
}
}
return null;
}
{
/* First: return<SCANS>T, valueT);
}
throw new IllegalArgumentException(
"Can not upgrade from an instance of " + baseType.getClass());
}
@Deprecated
// since 2.7; remove from 2.8
public static MapLikeType construct(Class<?> rawType, JavaType keyT,
JavaType valueT) {
// First: may need to fabricate TypeBindings (needed for refining into
// concrete collection types, as per [databind#1102])
TypeVariable<?>[] vars = rawType.getTypeParameters();
TypeBindings bindings;
if ((vars == null) || (vars.length != 2)) {
bindings = TypeBindings.emptyBindings();
} else {
bindings = TypeBindings.create(rawType, keyT, valueT);
}
return new MapLikeType(rawType, bindings, _bogusSuperClass(rawType),
null, keyT, valueT, null, null, false);
}
@Deprecated
// since 2.7
@Override
protected JavaType _narrow(Class<?> subclass) {
return new MapLikeType(subclass, _bindings, _superClass,
_superInterfaces, _keyType, _valueType, _valueHandler,
_typeHandler, _asStatic);
}
/**
* @since 2.7
*/
public MapLikeType withKeyType(JavaType keyType) {
if (keyType == _keyType) {
return this;
}
return new MapLikeType(_class, _bindings, _superClass,
_superInterfaces, keyType, _valueType, _valueHandler,
_typeHandler, _asStatic);
}
@Override
public JavaType withContentType(JavaType contentType) {
if (_valueType == contentType) {
return this;
}
return new MapLikeType(_class, _bindings, _superClass,
_superInterfaces, _keyType, contentType, _valueHandler,
_typeHandler, _asStatic);
}
@Override
public MapLikeType withTypeHandler(Object h) {
return new MapLikeType(_class, _bindings, _superClass,
_superInterfaces, _keyType, _valueType, _valueHandler, h,
_asStatic);
}
@Override
public MapLikeType withContentTypeHandler(Object h) {
return
JacksonDatabind, 65
<FILEB>
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: (%s) %s",
re.getClass().getName(), re.getMessage());
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
if (isFactoryMethod(am) && am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
if (am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
} else {
return null;
}
return new StdKeyDeserializer(kind, raw);
}
@Override
public Object deserializeKey(String key, DeserializationContext ctxt)
throws IOException
{
if (key == null) { // is this even legal call?
return null;
}
try {
Object result = _parse(key, ctxt);
if (result != null) {
return result;
}
} catch (Exception re) {
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: %s", re.getMessage());
<CHANGEE>
}
if (_keyClass.isEnum() && ctxt.getConfig().isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
return null;
}
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation");
}
public Class<?> getKeyClass() { return _keyClass; }
protected Object _parse(String key, DeserializationContext ctxt) throws Exception
{
switch (_kind) {
case TYPE_BOOLEAN:
if ("true".equals(key)) {
<FILEE>
<FILEB>
*/
if (ac.getParameterCount() == 1) {
Class<?> actArg = ac.getRawParameterType(0);
for (Class<?> expArg : argTypes) {
if (expArg == actArg) {
return ac.getAnnotated();
}
}
}
}
return null;
}
@Override
public Method findFactoryMethod(Class<?>... expArgTypes)
{
// So, of all single-arg static methods:
for (AnnotatedMethod am : _classInfo.getStaticMethods()) {
// 24-Oct-2016, tatu: Better ensure it only takes 1 arg, no matter what
<CHANGES>
if (isFactoryMethod(am)) {
<CHANGEE>
// And must take one of expected arg types (or supertype)
Class<?> actualArgType = am.getRawParameterType(0);
for (Class<?> expArgType : expArgTypes) {
// And one that matches what we would pass in
if (actualArgType.isAssignableFrom(expArgType)) {
return am.getAnnotated();
}
}
}
}
return null;
}
{
/* First: return<SCANS>util.Collection} or just something that acts like one.
*/
public boolean isTrueMapType() {
return Map.class.isAssignableFrom(_class);
}
/*
/**********************************************************
/* Standard methods
/**********************************************************
*/
@Override
public String toString() {
return String.format("[map-like type; class %s, %s -> %s]",
_class.getName(), _keyType, _valueType);
}
@Override
public boolean equals(Object o) {
if (o == this) return true;
if (o == null) return false;
if (o.getClass() != getClass()) return false;
MapLikeType other = (MapLikeType) o;
return (_class == other._class) && _keyType.equals(other._keyType)
&& _valueType.equals(other._valueType);
}
}
JacksonDatabind, 65
<FILEB>
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: (%s) %s",
re.getClass().getName(), re.getMessage());
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
if (isFactoryMethod(am) && am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
if (am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
} else {
return null;
}
return new StdKeyDeserializer(kind, raw);
}
@Override
public Object deserializeKey(String key, DeserializationContext ctxt)
throws IOException
{
if (key == null) { // is this even legal call?
return null;
}
try {
Object result = _parse(key, ctxt);
if (result != null) {
return result;
}
} catch (Exception re) {
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: %s", re.getMessage());
<CHANGEE>
}
if (_keyClass.isEnum() && ctxt.getConfig().isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
return null;
}
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation");
}
public Class<?> getKeyClass() { return _keyClass; }
protected Object _parse(String key, DeserializationContext ctxt) throws Exception
{
switch (_kind) {
case TYPE_BOOLEAN:
if ("true".equals(key)) {
<FILEE>
<FILEB>
*/
if (ac.getParameterCount() == 1) {
Class<?> actArg = ac.getRawParameterType(0);
for (Class<?> expArg : argTypes) {
if (expArg == actArg) {
return ac.getAnnotated();
}
}
}
}
return null;
}
@Override
public Method findFactoryMethod(Class<?>... expArgTypes)
{
// So, of all single-arg static methods:
for (AnnotatedMethod am : _classInfo.getStaticMethods()) {
// 24-Oct-2016, tatu: Better ensure it only takes 1 arg, no matter what
<CHANGES>
if (isFactoryMethod(am)) {
<CHANGEE>
// And must take one of expected arg types (or supertype)
Class<?> actualArgType = am.getRawParameterType(0);
for (Class<?> expArgType : expArgTypes) {
// And one that matches what we would pass in
if (actualArgType.isAssignableFrom(expArgType)) {
return am.getAnnotated();
}
}
}
}
return null;
}
{
/* First: return<SCANS> fieldName, List<String> foundSoFar);
public abstract List<JsonNode> findParents(String fieldName, List<JsonNode> foundSoFar);
/*
/**********************************************************
/* Public API, path handling
/**********************************************************
*/
/**
* Method that can be called on Object nodes, to access a property
* that has Object value; or if no such property exists, to create,
* add and return such Object node.
* If the node method is called on is not Object node,
* or if property exists and has value that is not Object node,
* {@link UnsupportedOperationException} is thrown
*/
public JsonNode with(String propertyName) {
throw new UnsupportedOperationException("JsonNode not of type ObjectNode (but "
+getClass().getName()+"), can not call with() on it");
}
/**
* Method that can be called on Object nodes, to access a property
* that has <code>Array</code> value; or if no such property exists, to create,
* add and return such Array node.
* If the node method is called on is not Object node,
* or if property exists and has value that is not Array node,
* {@link UnsupportedOperationException} is thrown
*/
public JsonNode withArray(String propertyName) {
throw new UnsupportedOperationException("JsonNode not of type ObjectNode (but "
+getClass().getName()+"), can not call withArray() on it");
}
/*
/**********************************************************
/* Public API, comparison
/**********************************************************
*/
/**
* Entry method for invoking customizable comparison, using passed-in
* {@link Comparator} object. Nodes will handle traversal of structured
* types (arrays, objects), but defer to comparator for scalar value
* comparisons. If a "natural" {@link Comparator} is passed -- one that
* simply calls <code>equals()</code> on one of arguments, passing the other
* -- implementation is the same as directly calling <code>equals()</code>
* on node.
*<p>
* Default implementation simply delegates to passed in <code>comparator</code>,
* with <code>this</code> as the first argument, and <code>other</code> as
* the second argument.
*
* @param comparator Object called to compare two scalar {@link JsonNode}
* instances, and return either 0 (are equals) or non
JacksonDatabind, 65
<FILEB>
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: (%s) %s",
re.getClass().getName(), re.getMessage());
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
if (isFactoryMethod(am) && am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
if (am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
} else {
return null;
}
return new StdKeyDeserializer(kind, raw);
}
@Override
public Object deserializeKey(String key, DeserializationContext ctxt)
throws IOException
{
if (key == null) { // is this even legal call?
return null;
}
try {
Object result = _parse(key, ctxt);
if (result != null) {
return result;
}
} catch (Exception re) {
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: %s", re.getMessage());
<CHANGEE>
}
if (_keyClass.isEnum() && ctxt.getConfig().isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
return null;
}
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation");
}
public Class<?> getKeyClass() { return _keyClass; }
protected Object _parse(String key, DeserializationContext ctxt) throws Exception
{
switch (_kind) {
case TYPE_BOOLEAN:
if ("true".equals(key)) {
<FILEE>
<FILEB>
*/
if (ac.getParameterCount() == 1) {
Class<?> actArg = ac.getRawParameterType(0);
for (Class<?> expArg : argTypes) {
if (expArg == actArg) {
return ac.getAnnotated();
}
}
}
}
return null;
}
@Override
public Method findFactoryMethod(Class<?>... expArgTypes)
{
// So, of all single-arg static methods:
for (AnnotatedMethod am : _classInfo.getStaticMethods()) {
// 24-Oct-2016, tatu: Better ensure it only takes 1 arg, no matter what
<CHANGES>
if (isFactoryMethod(am)) {
<CHANGEE>
// And must take one of expected arg types (or supertype)
Class<?> actualArgType = am.getRawParameterType(0);
for (Class<?> expArgType : expArgTypes) {
// And one that matches what we would pass in
if (actualArgType.isAssignableFrom(expArgType)) {
return am.getAnnotated();
}
}
}
}
return null;
}
{
/* First: return<SCANS>package com.fasterxml.jackson.databind.type;
import java.lang.reflect.Array;
import com.fasterxml.jackson.databind.JavaType;
/**
* Array types represent Java arrays, both primitive and object valued.
* Further, Object-valued arrays can have element type of any other
* legal {@link JavaType}.
*/
public final class ArrayType
extends TypeBase
{
private static final long serialVersionUID = 1L;
/**
* Type of elements in the array.
*/
protected final JavaType _componentType;
/**
* We will also keep track of shareable instance of empty array,
* since it usually needs to be constructed any way; and because
* it is essentially immutable and thus can be shared.
*/
protected final Object _emptyArray;
protected ArrayType(JavaType componentType, TypeBindings bindings, Object emptyInstance,
Object valueHandler, Object typeHandler, boolean asStatic)
{
// No super-class, interfaces, for now
super(emptyInstance.getClass(), bindings, null, null,
componentType.hashCode(),
valueHandler, typeHandler, asStatic);
_componentType = componentType;
_emptyArray = emptyInstance;
}
public static ArrayType construct(JavaType componentType, TypeBindings bindings) {
return construct(componentType, bindings, null, null);
}
public static ArrayType construct(JavaType componentType, TypeBindings bindings,
Object valueHandler, Object typeHandler) {
// Figuring out raw class for generic array is actually bit tricky...
Object emptyInstance = Array.newInstance(componentType.getRawClass(), 0);
return new ArrayType(componentType, bindings, emptyInstance, valueHandler, typeHandler, false);
}
@Override
public JavaType withContentType(JavaType contentType) {
Object emptyInstance = Array.newInstance(contentType.getRawClass(), 0);
return new ArrayType(contentType, _bindings, emptyInstance,
_valueHandler, _typeHandler, _asStatic);
}
@Override
public ArrayType withTypeHandler(Object h)
{
if (h == _typeHandler) {
return this;
}
return new ArrayType(_componentType, _bindings, _emptyArray, _valueHandler, h, _asStatic);
}
@Override
public Array
JacksonDatabind, 65
<FILEB>
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: (%s) %s",
re.getClass().getName(), re.getMessage());
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
if (isFactoryMethod(am) && am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
if (am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
} else {
return null;
}
return new StdKeyDeserializer(kind, raw);
}
@Override
public Object deserializeKey(String key, DeserializationContext ctxt)
throws IOException
{
if (key == null) { // is this even legal call?
return null;
}
try {
Object result = _parse(key, ctxt);
if (result != null) {
return result;
}
} catch (Exception re) {
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: %s", re.getMessage());
<CHANGEE>
}
if (_keyClass.isEnum() && ctxt.getConfig().isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
return null;
}
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation");
}
public Class<?> getKeyClass() { return _keyClass; }
protected Object _parse(String key, DeserializationContext ctxt) throws Exception
{
switch (_kind) {
case TYPE_BOOLEAN:
if ("true".equals(key)) {
<FILEE>
<FILEB>
*/
if (ac.getParameterCount() == 1) {
Class<?> actArg = ac.getRawParameterType(0);
for (Class<?> expArg : argTypes) {
if (expArg == actArg) {
return ac.getAnnotated();
}
}
}
}
return null;
}
@Override
public Method findFactoryMethod(Class<?>... expArgTypes)
{
// So, of all single-arg static methods:
for (AnnotatedMethod am : _classInfo.getStaticMethods()) {
// 24-Oct-2016, tatu: Better ensure it only takes 1 arg, no matter what
<CHANGES>
if (isFactoryMethod(am)) {
<CHANGEE>
// And must take one of expected arg types (or supertype)
Class<?> actualArgType = am.getRawParameterType(0);
for (Class<?> expArgType : expArgTypes) {
// And one that matches what we would pass in
if (actualArgType.isAssignableFrom(expArgType)) {
return am.getAnnotated();
}
}
}
}
return null;
}
{
/* First: return<SCANS>; }
/**
* For some odd reason, modifiers for array classes would
* claim they are abstract types. Not so, at least for our
* purposes.
*/
@Override
public boolean isConcrete() { return true; }
@Override
public boolean hasGenericTypes() {
// arrays are not parameterized, but element type may be:
return _componentType.hasGenericTypes();
}
/*
/**********************************************************
/* Public API
/**********************************************************
*/
@Override
public boolean isContainerType() { return true; }
@Override
public JavaType getContentType() { return _componentType; }
@Override
public Object getContentValueHandler() {
return _componentType.getValueHandler();
}
@Override
public Object getContentTypeHandler() {
return _componentType.getTypeHandler();
}
@Override
public boolean hasHandlers() {
return super.hasHandlers() || _componentType.hasHandlers();
}
@Override
public StringBuilder getGenericSignature(StringBuilder sb) {
sb.append('[');
return _componentType.getGenericSignature(sb);
}
@Override
public StringBuilder getErasedSignature(StringBuilder sb) {
sb.append('[');
return _componentType.getErasedSignature(sb);
}
/*
/**********************************************************
/* Standard methods
/**********************************************************
*/
@Override
public String toString()
{
return "[array type, component type: "+_componentType+"]";
}
@Override
public boolean equals(Object o)
{
if (o == this) return true;
if (o == null) return false;
if (o.getClass() != getClass()) return false;
ArrayType other = (ArrayType) o;
return _componentType.equals(other._componentType);
}
}
JacksonDatabind, 65
<FILEB>
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: (%s) %s",
re.getClass().getName(), re.getMessage());
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
if (isFactoryMethod(am) && am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
if (am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
} else {
return null;
}
return new StdKeyDeserializer(kind, raw);
}
@Override
public Object deserializeKey(String key, DeserializationContext ctxt)
throws IOException
{
if (key == null) { // is this even legal call?
return null;
}
try {
Object result = _parse(key, ctxt);
if (result != null) {
return result;
}
} catch (Exception re) {
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: %s", re.getMessage());
<CHANGEE>
}
if (_keyClass.isEnum() && ctxt.getConfig().isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
return null;
}
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation");
}
public Class<?> getKeyClass() { return _keyClass; }
protected Object _parse(String key, DeserializationContext ctxt) throws Exception
{
switch (_kind) {
case TYPE_BOOLEAN:
if ("true".equals(key)) {
<FILEE>
<FILEB>
*/
if (ac.getParameterCount() == 1) {
Class<?> actArg = ac.getRawParameterType(0);
for (Class<?> expArg : argTypes) {
if (expArg == actArg) {
return ac.getAnnotated();
}
}
}
}
return null;
}
@Override
public Method findFactoryMethod(Class<?>... expArgTypes)
{
// So, of all single-arg static methods:
for (AnnotatedMethod am : _classInfo.getStaticMethods()) {
// 24-Oct-2016, tatu: Better ensure it only takes 1 arg, no matter what
<CHANGES>
if (isFactoryMethod(am)) {
<CHANGEE>
// And must take one of expected arg types (or supertype)
Class<?> actualArgType = am.getRawParameterType(0);
for (Class<?> expArgType : expArgTypes) {
// And one that matches what we would pass in
if (actualArgType.isAssignableFrom(expArgType)) {
return am.getAnnotated();
}
}
}
}
return null;
}
{
/* First: return<SCANS>
if ((intr == null) || (_member == null)) {
return v0;
}
JsonInclude.Value v = intr.findPropertyInclusion(_member);
if (v == null) {
return v0;
}
return v0.withOverrides(v);
}
@Override public String getName() { return _name.getSimpleName(); }
@Override public PropertyName getFullName() { return _name; }
@Override public JavaType getType() { return _type; }
@Override public PropertyName getWrapperName() { return _wrapperName; }
@Override public boolean isRequired() { return _metadata.isRequired(); }
@Override public PropertyMetadata getMetadata() { return _metadata; }
@Override public AnnotatedMember getMember() { return _member; }
@Override
public boolean isVirtual() { return false; }
/**
* Implementation of this method throws
* {@link UnsupportedOperationException}, since instances of this
* implementation should not be used as part of actual structure
* visited. Rather, other implementations should handle it.
*/
@Override
public void depositSchemaProperty(JsonObjectFormatVisitor objectVisitor,
SerializerProvider provider) {
throw new UnsupportedOperationException("Instances of "+getClass().getName()+" should not get visited");
}
}
}
JacksonDatabind, 65
<FILEB>
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: (%s) %s",
re.getClass().getName(), re.getMessage());
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
if (isFactoryMethod(am) && am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
if (am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
} else {
return null;
}
return new StdKeyDeserializer(kind, raw);
}
@Override
public Object deserializeKey(String key, DeserializationContext ctxt)
throws IOException
{
if (key == null) { // is this even legal call?
return null;
}
try {
Object result = _parse(key, ctxt);
if (result != null) {
return result;
}
} catch (Exception re) {
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: %s", re.getMessage());
<CHANGEE>
}
if (_keyClass.isEnum() && ctxt.getConfig().isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
return null;
}
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation");
}
public Class<?> getKeyClass() { return _keyClass; }
protected Object _parse(String key, DeserializationContext ctxt) throws Exception
{
switch (_kind) {
case TYPE_BOOLEAN:
if ("true".equals(key)) {
<FILEE>
<FILEB>
*/
if (ac.getParameterCount() == 1) {
Class<?> actArg = ac.getRawParameterType(0);
for (Class<?> expArg : argTypes) {
if (expArg == actArg) {
return ac.getAnnotated();
}
}
}
}
return null;
}
@Override
public Method findFactoryMethod(Class<?>... expArgTypes)
{
// So, of all single-arg static methods:
for (AnnotatedMethod am : _classInfo.getStaticMethods()) {
// 24-Oct-2016, tatu: Better ensure it only takes 1 arg, no matter what
<CHANGES>
if (isFactoryMethod(am)) {
<CHANGEE>
// And must take one of expected arg types (or supertype)
Class<?> actualArgType = am.getRawParameterType(0);
for (Class<?> expArgType : expArgTypes) {
// And one that matches what we would pass in
if (actualArgType.isAssignableFrom(expArgType)) {
return am.getAnnotated();
}
}
}
}
return null;
}
{
/* First: return<SCANS> Method that can be called to locate value to be injected for this
* property, if it is configured for this.
*/
public Object findInjectableValue(DeserializationContext context, Object beanInstance)
{
if (_injectableValueId == null) {
throw new IllegalStateException("Property '"+getName()
+"' (type "+getClass().getName()+") has no injectable value id configured");
}
return context.findInjectableValue(_injectableValueId, this, beanInstance);
}
/**
* Method to find value to inject, and inject it to this property.
*/
public void inject(DeserializationContext context, Object beanInstance)
throws IOException
{
set(beanInstance, findInjectableValue(context, beanInstance));
}
/*
/**********************************************************
/* BeanProperty impl
/**********************************************************
*/
@Override
public <A extends Annotation> A getAnnotation(Class<A> acls) {
if (_annotated == null) {
return null;
}
return _annotated.getAnnotation(acls);
}
@Override public AnnotatedMember getMember() { return _annotated; }
@Override public int getCreatorIndex() {
return _creatorIndex;
}
/*
/**********************************************************
/* Overridden methods
/**********************************************************
*/
@Override
public void deserializeAndSet(JsonParser p, DeserializationContext ctxt,
Object instance) throws IOException
{
set(instance, deserialize(p, ctxt));
}
@Override
public Object deserializeSetAndReturn(JsonParser p,
DeserializationContext ctxt, Object instance) throws IOException
{
return setAndReturn(instance, deserialize(p, ctxt));
}
@Override
public void set(Object instance, Object value) throws IOException
{
/* Hmmmh. Should we return quietly (NOP), or error?
* Perhaps better to throw an exception, since it's generally an error.
*/
if (_fallbackSetter == null) {
throw new IllegalStateException("No fallback setter/field defined: can not use creator property for "
+getClass().getName());
}
_fallbackSetter.set(instance, value);
}
@Override
public Object setAndReturn(Object instance, Object value) throws IOException
{
if (_fallbackSetter == null) {
throw new IllegalStateException("No fallback setter/field defined: can not use creator property for "
JacksonDatabind, 65
<FILEB>
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: (%s) %s",
re.getClass().getName(), re.getMessage());
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
if (isFactoryMethod(am) && am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
if (am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
} else {
return null;
}
return new StdKeyDeserializer(kind, raw);
}
@Override
public Object deserializeKey(String key, DeserializationContext ctxt)
throws IOException
{
if (key == null) { // is this even legal call?
return null;
}
try {
Object result = _parse(key, ctxt);
if (result != null) {
return result;
}
} catch (Exception re) {
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: %s", re.getMessage());
<CHANGEE>
}
if (_keyClass.isEnum() && ctxt.getConfig().isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
return null;
}
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation");
}
public Class<?> getKeyClass() { return _keyClass; }
protected Object _parse(String key, DeserializationContext ctxt) throws Exception
{
switch (_kind) {
case TYPE_BOOLEAN:
if ("true".equals(key)) {
<FILEE>
<FILEB>
*/
if (ac.getParameterCount() == 1) {
Class<?> actArg = ac.getRawParameterType(0);
for (Class<?> expArg : argTypes) {
if (expArg == actArg) {
return ac.getAnnotated();
}
}
}
}
return null;
}
@Override
public Method findFactoryMethod(Class<?>... expArgTypes)
{
// So, of all single-arg static methods:
for (AnnotatedMethod am : _classInfo.getStaticMethods()) {
// 24-Oct-2016, tatu: Better ensure it only takes 1 arg, no matter what
<CHANGES>
if (isFactoryMethod(am)) {
<CHANGEE>
// And must take one of expected arg types (or supertype)
Class<?> actualArgType = am.getRawParameterType(0);
for (Class<?> expArgType : expArgTypes) {
// And one that matches what we would pass in
if (actualArgType.isAssignableFrom(expArgType)) {
return am.getAnnotated();
}
}
}
}
return null;
}
{
/* First: return<SCANS>
+getClass().getName());
}
return _fallbackSetter.setAndReturn(instance, value);
}
@Override
public Object getInjectableValueId() {
return _injectableValueId;
}
@Override
public String toString() { return "[creator property, name '"+getName()+"'; inject id '"+_injectableValueId+"']"; }
}
JacksonDatabind, 65
<FILEB>
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: (%s) %s",
re.getClass().getName(), re.getMessage());
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
if (isFactoryMethod(am) && am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
if (am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
} else {
return null;
}
return new StdKeyDeserializer(kind, raw);
}
@Override
public Object deserializeKey(String key, DeserializationContext ctxt)
throws IOException
{
if (key == null) { // is this even legal call?
return null;
}
try {
Object result = _parse(key, ctxt);
if (result != null) {
return result;
}
} catch (Exception re) {
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: %s", re.getMessage());
<CHANGEE>
}
if (_keyClass.isEnum() && ctxt.getConfig().isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
return null;
}
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation");
}
public Class<?> getKeyClass() { return _keyClass; }
protected Object _parse(String key, DeserializationContext ctxt) throws Exception
{
switch (_kind) {
case TYPE_BOOLEAN:
if ("true".equals(key)) {
<FILEE>
<FILEB>
*/
if (ac.getParameterCount() == 1) {
Class<?> actArg = ac.getRawParameterType(0);
for (Class<?> expArg : argTypes) {
if (expArg == actArg) {
return ac.getAnnotated();
}
}
}
}
return null;
}
@Override
public Method findFactoryMethod(Class<?>... expArgTypes)
{
// So, of all single-arg static methods:
for (AnnotatedMethod am : _classInfo.getStaticMethods()) {
// 24-Oct-2016, tatu: Better ensure it only takes 1 arg, no matter what
<CHANGES>
if (isFactoryMethod(am)) {
<CHANGEE>
// And must take one of expected arg types (or supertype)
Class<?> actualArgType = am.getRawParameterType(0);
for (Class<?> expArgType : expArgTypes) {
// And one that matches what we would pass in
if (actualArgType.isAssignableFrom(expArgType)) {
return am.getAnnotated();
}
}
}
}
return null;
}
{
/* First: return<SCANS>
final MapperConfig<?> config = getConfig();
HandlerInstantiator hi = config.getHandlerInstantiator();
ObjectIdGenerator<?> gen = (hi == null) ? null : hi.objectIdGeneratorInstance(config, annotated, implClass);
if (gen == null) {
gen = (ObjectIdGenerator<?>) ClassUtil.createInstance(implClass,
config.canOverrideAccessModifiers());
}
return gen.forScope(objectIdInfo.getScope());
}
public ObjectIdResolver objectIdResolverInstance(Annotated annotated, ObjectIdInfo objectIdInfo)
{
Class<? extends ObjectIdResolver> implClass = objectIdInfo.getResolverType();
final MapperConfig<?> config = getConfig();
HandlerInstantiator hi = config.getHandlerInstantiator();
ObjectIdResolver resolver = (hi == null) ? null : hi.resolverIdGeneratorInstance(config, annotated, implClass);
if (resolver == null) {
resolver = ClassUtil.createInstance(implClass, config.canOverrideAccessModifiers());
}
return resolver;
}
/**
* Helper method to use to construct a {@link Converter}, given a definition
* that may be either actual converter instance, or Class for instantiating one.
*
* @since 2.2
*/
@SuppressWarnings("unchecked")
public Converter<Object,Object> converterInstance(Annotated annotated,
Object converterDef)
throws JsonMappingException
{
if (converterDef == null) {
return null;
}
if (converterDef instanceof Converter<?,?>) {
return (Converter<Object,Object>) converterDef;
}
if (!(converterDef instanceof Class)) {
throw new IllegalStateException("AnnotationIntrospector returned Converter definition of type "
+converterDef.getClass().getName()+"; expected type Converter or Class<Converter> instead");
}
Class<?> converterClass = (Class<?>)converterDef;
// there are some known "no class" markers to consider too:
if (converterClass == Converter.None.class || ClassUtil.isBogusClass(converterClass)) {
return null;
}
if (!Converter.class.isAssignableFrom(converterClass)) {
throw new IllegalStateException("AnnotationIntrospector returned Class "
+converterClass.getName()+"; expected Class<Converter>");
}
final MapperConfig<?> config = getConfig();
HandlerInstantiator hi = config.getHandlerInstantiator();
Converter
JacksonDatabind, 65
<FILEB>
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: (%s) %s",
re.getClass().getName(), re.getMessage());
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
if (isFactoryMethod(am) && am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
if (am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
} else {
return null;
}
return new StdKeyDeserializer(kind, raw);
}
@Override
public Object deserializeKey(String key, DeserializationContext ctxt)
throws IOException
{
if (key == null) { // is this even legal call?
return null;
}
try {
Object result = _parse(key, ctxt);
if (result != null) {
return result;
}
} catch (Exception re) {
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: %s", re.getMessage());
<CHANGEE>
}
if (_keyClass.isEnum() && ctxt.getConfig().isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
return null;
}
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation");
}
public Class<?> getKeyClass() { return _keyClass; }
protected Object _parse(String key, DeserializationContext ctxt) throws Exception
{
switch (_kind) {
case TYPE_BOOLEAN:
if ("true".equals(key)) {
<FILEE>
<FILEB>
*/
if (ac.getParameterCount() == 1) {
Class<?> actArg = ac.getRawParameterType(0);
for (Class<?> expArg : argTypes) {
if (expArg == actArg) {
return ac.getAnnotated();
}
}
}
}
return null;
}
@Override
public Method findFactoryMethod(Class<?>... expArgTypes)
{
// So, of all single-arg static methods:
for (AnnotatedMethod am : _classInfo.getStaticMethods()) {
// 24-Oct-2016, tatu: Better ensure it only takes 1 arg, no matter what
<CHANGES>
if (isFactoryMethod(am)) {
<CHANGEE>
// And must take one of expected arg types (or supertype)
Class<?> actualArgType = am.getRawParameterType(0);
for (Class<?> expArgType : expArgTypes) {
// And one that matches what we would pass in
if (actualArgType.isAssignableFrom(expArgType)) {
return am.getAnnotated();
}
}
}
}
return null;
}
{
/* First: return<SCANS> provider.isEnabled(SerializationFeature.WRITE_SINGLE_ELEM_ARRAYS_UNWRAPPED))
|| (_unwrapSingle == Boolean.TRUE)) {
serializeContents(value, gen, provider);
return;
}
}
gen.writeStartArray(len);
serializeContents(value, gen, provider);
gen.writeEndArray();
}
@Override
public void serializeContents(Object[] value, JsonGenerator gen, SerializerProvider provider) throws IOException
{
final int len = value.length;
if (len == 0) {
return;
}
if (_elementSerializer != null) {
serializeContentsUsing(value, gen, provider, _elementSerializer);
return;
}
if (_valueTypeSerializer != null) {
serializeTypedContents(value, gen, provider);
return;
}
int i = 0;
Object elem = null;
try {
PropertySerializerMap serializers = _dynamicSerializers;
for (; i < len; ++i) {
elem = value[i];
if (elem == null) {
provider.defaultSerializeNull(gen);
continue;
}
Class<?> cc = elem.getClass();
JsonSerializer<Object> serializer = serializers.serializerFor(cc);
if (serializer == null) {
// To fix [JACKSON-508]
if (_elementType.hasGenericTypes()) {
serializer = _findAndAddDynamic(serializers,
provider.constructSpecializedType(_elementType, cc), provider);
} else {
serializer = _findAndAddDynamic(serializers, cc, provider);
}
}
serializer.serialize(elem, gen, provider);
}
} catch (IOException ioe) {
throw ioe;
} catch (Exception e) {
// [JACKSON-55] Need to add reference information
/* 05-Mar-2009, tatu: But one nasty edge is when we get
* StackOverflow: usually due to infinite loop. But that gets
* hidden within an InvocationTargetException...
*/
Throwable t = e;
while (t instanceof InvocationTargetException && t.getCause() != null) {
t = t.getCause();
}
if (t instanceof Error) {
throw (Error) t;
}
throw JsonMappingException.wrapWithPath(t
JacksonDatabind, 65
<FILEB>
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: (%s) %s",
re.getClass().getName(), re.getMessage());
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
if (isFactoryMethod(am) && am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
if (am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
} else {
return null;
}
return new StdKeyDeserializer(kind, raw);
}
@Override
public Object deserializeKey(String key, DeserializationContext ctxt)
throws IOException
{
if (key == null) { // is this even legal call?
return null;
}
try {
Object result = _parse(key, ctxt);
if (result != null) {
return result;
}
} catch (Exception re) {
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: %s", re.getMessage());
<CHANGEE>
}
if (_keyClass.isEnum() && ctxt.getConfig().isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
return null;
}
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation");
}
public Class<?> getKeyClass() { return _keyClass; }
protected Object _parse(String key, DeserializationContext ctxt) throws Exception
{
switch (_kind) {
case TYPE_BOOLEAN:
if ("true".equals(key)) {
<FILEE>
<FILEB>
*/
if (ac.getParameterCount() == 1) {
Class<?> actArg = ac.getRawParameterType(0);
for (Class<?> expArg : argTypes) {
if (expArg == actArg) {
return ac.getAnnotated();
}
}
}
}
return null;
}
@Override
public Method findFactoryMethod(Class<?>... expArgTypes)
{
// So, of all single-arg static methods:
for (AnnotatedMethod am : _classInfo.getStaticMethods()) {
// 24-Oct-2016, tatu: Better ensure it only takes 1 arg, no matter what
<CHANGES>
if (isFactoryMethod(am)) {
<CHANGEE>
// And must take one of expected arg types (or supertype)
Class<?> actualArgType = am.getRawParameterType(0);
for (Class<?> expArgType : expArgTypes) {
// And one that matches what we would pass in
if (actualArgType.isAssignableFrom(expArgType)) {
return am.getAnnotated();
}
}
}
}
return null;
}
{
/* First: return<SCANS>, elem, i);
}
}
public void serializeContentsUsing(Object[] value, JsonGenerator jgen, SerializerProvider provider,
JsonSerializer<Object> ser) throws IOException
{
final int len = value.length;
final TypeSerializer typeSer = _valueTypeSerializer;
int i = 0;
Object elem = null;
try {
for (; i < len; ++i) {
elem = value[i];
if (elem == null) {
provider.defaultSerializeNull(jgen);
continue;
}
if (typeSer == null) {
ser.serialize(elem, jgen, provider);
} else {
ser.serializeWithType(elem, jgen, provider, typeSer);
}
}
} catch (IOException ioe) {
throw ioe;
} catch (Exception e) {
Throwable t = e;
while (t instanceof InvocationTargetException && t.getCause() != null) {
t = t.getCause();
}
if (t instanceof Error) {
throw (Error) t;
}
throw JsonMappingException.wrapWithPath(t, elem, i);
}
}
public void serializeTypedContents(Object[] value, JsonGenerator jgen, SerializerProvider provider) throws IOException
{
final int len = value.length;
final TypeSerializer typeSer = _valueTypeSerializer;
int i = 0;
Object elem = null;
try {
PropertySerializerMap serializers = _dynamicSerializers;
for (; i < len; ++i) {
elem = value[i];
if (elem == null) {
provider.defaultSerializeNull(jgen);
continue;
}
Class<?> cc = elem.getClass();
JsonSerializer<Object> serializer = serializers.serializerFor(cc);
if (serializer == null) {
serializer = _findAndAddDynamic(serializers, cc, provider);
}
serializer.serializeWithType(elem, jgen, provider, typeSer);
}
} catch (IOException ioe) {
throw ioe;
} catch (Exception e) {
Throwable t = e;
while (t instanceof InvocationTargetException && t.getCause() != null) {
t = t.getCause();
}
if (t instanceof Error) {
throw (Error) t;
}
throw JsonMappingException
JacksonDatabind, 65
<FILEB>
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: (%s) %s",
re.getClass().getName(), re.getMessage());
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
if (isFactoryMethod(am) && am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
if (am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
} else {
return null;
}
return new StdKeyDeserializer(kind, raw);
}
@Override
public Object deserializeKey(String key, DeserializationContext ctxt)
throws IOException
{
if (key == null) { // is this even legal call?
return null;
}
try {
Object result = _parse(key, ctxt);
if (result != null) {
return result;
}
} catch (Exception re) {
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: %s", re.getMessage());
<CHANGEE>
}
if (_keyClass.isEnum() && ctxt.getConfig().isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
return null;
}
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation");
}
public Class<?> getKeyClass() { return _keyClass; }
protected Object _parse(String key, DeserializationContext ctxt) throws Exception
{
switch (_kind) {
case TYPE_BOOLEAN:
if ("true".equals(key)) {
<FILEE>
<FILEB>
*/
if (ac.getParameterCount() == 1) {
Class<?> actArg = ac.getRawParameterType(0);
for (Class<?> expArg : argTypes) {
if (expArg == actArg) {
return ac.getAnnotated();
}
}
}
}
return null;
}
@Override
public Method findFactoryMethod(Class<?>... expArgTypes)
{
// So, of all single-arg static methods:
for (AnnotatedMethod am : _classInfo.getStaticMethods()) {
// 24-Oct-2016, tatu: Better ensure it only takes 1 arg, no matter what
<CHANGES>
if (isFactoryMethod(am)) {
<CHANGEE>
// And must take one of expected arg types (or supertype)
Class<?> actualArgType = am.getRawParameterType(0);
for (Class<?> expArgType : expArgTypes) {
// And one that matches what we would pass in
if (actualArgType.isAssignableFrom(expArgType)) {
return am.getAnnotated();
}
}
}
}
return null;
}
{
/* First: return<SCANS>Context ctxt, JavaType type)
throws JsonMappingException
{
// Since we are calling from `resolve`, we should NOT try to contextualize yet;
// contextualization will only occur at a later point
return ctxt.findNonContextualValueDeserializer(type);
}
protected JsonDeserializer<Object> _clearIfStdImpl(JsonDeserializer<Object> deser) {
return ClassUtil.isJacksonStdImpl(deser) ? null : deser;
}
/**
* We only use contextualization for optimizing the case where no customization
* occurred; if so, can slip in a more streamlined version.
*/
@Override
public JsonDeserializer<?> createContextual(DeserializationContext ctxt,
BeanProperty property) throws JsonMappingException
{
// 20-Apr-2014, tatu: If nothing custom, let's use "vanilla" instance,
// simpler and can avoid some of delegation
if ((_stringDeserializer == null) && (_numberDeserializer == null)
&& (_mapDeserializer == null) && (_listDeserializer == null)
&& getClass() == UntypedObjectDeserializer.class) {
return Vanilla.std;
}
return this;
}
protected JsonDeserializer<?> _withResolved(JsonDeserializer<?> mapDeser,
JsonDeserializer<?> listDeser,
JsonDeserializer<?> stringDeser, JsonDeserializer<?> numberDeser) {
return new UntypedObjectDeserializer(this,
mapDeser, listDeser, stringDeser, numberDeser);
}
/*
/**********************************************************
/* Deserializer API
/**********************************************************
*/
/* 07-Nov-2014, tatu: When investigating [databind#604], realized that it makes
* sense to also mark this is cachable, since lookup not exactly free, and
* since it's not uncommon to "read anything"
*/
@Override
public boolean isCachable() {
/* 26-Mar-2015, tatu: With respect to [databind#735], there are concerns over
* cachability. It seems like we SHOULD be safe here; but just in case there
* are problems with false sharing, this may need to be revisited.
*/
return true;
}
@
JacksonDatabind, 65
<FILEB>
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: (%s) %s",
re.getClass().getName(), re.getMessage());
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
if (isFactoryMethod(am) && am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
if (am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
} else {
return null;
}
return new StdKeyDeserializer(kind, raw);
}
@Override
public Object deserializeKey(String key, DeserializationContext ctxt)
throws IOException
{
if (key == null) { // is this even legal call?
return null;
}
try {
Object result = _parse(key, ctxt);
if (result != null) {
return result;
}
} catch (Exception re) {
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: %s", re.getMessage());
<CHANGEE>
}
if (_keyClass.isEnum() && ctxt.getConfig().isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
return null;
}
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation");
}
public Class<?> getKeyClass() { return _keyClass; }
protected Object _parse(String key, DeserializationContext ctxt) throws Exception
{
switch (_kind) {
case TYPE_BOOLEAN:
if ("true".equals(key)) {
<FILEE>
<FILEB>
*/
if (ac.getParameterCount() == 1) {
Class<?> actArg = ac.getRawParameterType(0);
for (Class<?> expArg : argTypes) {
if (expArg == actArg) {
return ac.getAnnotated();
}
}
}
}
return null;
}
@Override
public Method findFactoryMethod(Class<?>... expArgTypes)
{
// So, of all single-arg static methods:
for (AnnotatedMethod am : _classInfo.getStaticMethods()) {
// 24-Oct-2016, tatu: Better ensure it only takes 1 arg, no matter what
<CHANGES>
if (isFactoryMethod(am)) {
<CHANGEE>
// And must take one of expected arg types (or supertype)
Class<?> actualArgType = am.getRawParameterType(0);
for (Class<?> expArgType : expArgTypes) {
// And one that matches what we would pass in
if (actualArgType.isAssignableFrom(expArgType)) {
return am.getAnnotated();
}
}
}
}
return null;
}
{
/* First: return<SCANS>package com.fasterxml.jackson.databind.deser.impl;
import com.fasterxml.jackson.annotation.ObjectIdGenerator;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
// Simple placeholder
public class PropertyBasedObjectIdGenerator
extends ObjectIdGenerators.PropertyGenerator
{
private static final long serialVersionUID = 1L;
public PropertyBasedObjectIdGenerator(Class<?> scope) {
super(scope);
}
@Override
public Object generateId(Object forPojo) {
throw new UnsupportedOperationException();
}
@Override
public ObjectIdGenerator<Object> forScope(Class<?> scope) {
return (scope == _scope) ? this : new PropertyBasedObjectIdGenerator(scope);
}
@Override
public ObjectIdGenerator<Object> newForSerialization(Object context) {
return this;
}
@Override
public com.fasterxml.jackson.annotation.ObjectIdGenerator.IdKey key(Object key) {
if (key == null) {
return null;
}
// should we use general type for all; or type of property itself?
return new IdKey(getClass(), _scope, key);
}
}
JacksonDatabind, 65
<FILEB>
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: (%s) %s",
re.getClass().getName(), re.getMessage());
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
if (isFactoryMethod(am) && am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
if (am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
} else {
return null;
}
return new StdKeyDeserializer(kind, raw);
}
@Override
public Object deserializeKey(String key, DeserializationContext ctxt)
throws IOException
{
if (key == null) { // is this even legal call?
return null;
}
try {
Object result = _parse(key, ctxt);
if (result != null) {
return result;
}
} catch (Exception re) {
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: %s", re.getMessage());
<CHANGEE>
}
if (_keyClass.isEnum() && ctxt.getConfig().isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
return null;
}
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation");
}
public Class<?> getKeyClass() { return _keyClass; }
protected Object _parse(String key, DeserializationContext ctxt) throws Exception
{
switch (_kind) {
case TYPE_BOOLEAN:
if ("true".equals(key)) {
<FILEE>
<FILEB>
*/
if (ac.getParameterCount() == 1) {
Class<?> actArg = ac.getRawParameterType(0);
for (Class<?> expArg : argTypes) {
if (expArg == actArg) {
return ac.getAnnotated();
}
}
}
}
return null;
}
@Override
public Method findFactoryMethod(Class<?>... expArgTypes)
{
// So, of all single-arg static methods:
for (AnnotatedMethod am : _classInfo.getStaticMethods()) {
// 24-Oct-2016, tatu: Better ensure it only takes 1 arg, no matter what
<CHANGES>
if (isFactoryMethod(am)) {
<CHANGEE>
// And must take one of expected arg types (or supertype)
Class<?> actualArgType = am.getRawParameterType(0);
for (Class<?> expArgType : expArgTypes) {
// And one that matches what we would pass in
if (actualArgType.isAssignableFrom(expArgType)) {
return am.getAnnotated();
}
}
}
}
return null;
}
{
/* First: return<SCANS>package com.fasterxml.jackson.databind.ser.impl;
import com.fasterxml.jackson.annotation.ObjectIdGenerator;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
import com.fasterxml.jackson.databind.introspect.ObjectIdInfo;
import com.fasterxml.jackson.databind.ser.*;
public class PropertyBasedObjectIdGenerator
extends ObjectIdGenerators.PropertyGenerator
{
private static final long serialVersionUID = 1L;
protected final BeanPropertyWriter _property;
public PropertyBasedObjectIdGenerator(ObjectIdInfo oid, BeanPropertyWriter prop)
{
this(oid.getScope(), prop);
}
protected PropertyBasedObjectIdGenerator(Class<?> scope, BeanPropertyWriter prop)
{
super(scope);
_property = prop;
}
/**
* We must override this method, to prevent errors when scopes are the same,
* but underlying class (on which to access property) is different.
*/
@Override
public boolean canUseFor(ObjectIdGenerator<?> gen) {
if (gen.getClass() == getClass()) {
PropertyBasedObjectIdGenerator other = (PropertyBasedObjectIdGenerator) gen;
if (other.getScope() == _scope) {
/* 26-Jul-2012, tatu: This is actually not enough, because the property
* accessor within BeanPropertyWriter won't work for other property fields
* (see [https://github.com/FasterXML/jackson-module-jaxb-annotations/issues/9]
* for details).
* So we need to verify that underlying property is actually the same.
*/
return (other._property == _property);
}
}
return false;
}
@Override
public Object generateId(Object forPojo) {
try {
return _property.get(forPojo);
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
throw new IllegalStateException("Problem accessing property '"
+_property.getName()+"': "+e.getMessage(), e);
}
}
@Override
public ObjectIdGenerator<Object> forScope(Class<?> scope) {
return (scope == _scope) ? this : new PropertyBasedObjectIdGenerator(scope, _property);
}
@Override
public ObjectIdGenerator<Object> newForSerialization(Object context) {
// No state
JacksonDatabind, 65
<FILEB>
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: (%s) %s",
re.getClass().getName(), re.getMessage());
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
if (isFactoryMethod(am) && am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
if (am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
} else {
return null;
}
return new StdKeyDeserializer(kind, raw);
}
@Override
public Object deserializeKey(String key, DeserializationContext ctxt)
throws IOException
{
if (key == null) { // is this even legal call?
return null;
}
try {
Object result = _parse(key, ctxt);
if (result != null) {
return result;
}
} catch (Exception re) {
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: %s", re.getMessage());
<CHANGEE>
}
if (_keyClass.isEnum() && ctxt.getConfig().isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
return null;
}
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation");
}
public Class<?> getKeyClass() { return _keyClass; }
protected Object _parse(String key, DeserializationContext ctxt) throws Exception
{
switch (_kind) {
case TYPE_BOOLEAN:
if ("true".equals(key)) {
<FILEE>
<FILEB>
*/
if (ac.getParameterCount() == 1) {
Class<?> actArg = ac.getRawParameterType(0);
for (Class<?> expArg : argTypes) {
if (expArg == actArg) {
return ac.getAnnotated();
}
}
}
}
return null;
}
@Override
public Method findFactoryMethod(Class<?>... expArgTypes)
{
// So, of all single-arg static methods:
for (AnnotatedMethod am : _classInfo.getStaticMethods()) {
// 24-Oct-2016, tatu: Better ensure it only takes 1 arg, no matter what
<CHANGES>
if (isFactoryMethod(am)) {
<CHANGEE>
// And must take one of expected arg types (or supertype)
Class<?> actualArgType = am.getRawParameterType(0);
for (Class<?> expArgType : expArgTypes) {
// And one that matches what we would pass in
if (actualArgType.isAssignableFrom(expArgType)) {
return am.getAnnotated();
}
}
}
}
return null;
}
{
/* First: return<SCANS>, can return this
return this;
}
@Override
public com.fasterxml.jackson.annotation.ObjectIdGenerator.IdKey key(Object key) {
if (key == null) {
return null;
}
// should we use general type for all; or type of property itself?
return new IdKey(getClass(), _scope, key);
}
}
JacksonDatabind, 65
<FILEB>
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: (%s) %s",
re.getClass().getName(), re.getMessage());
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
if (isFactoryMethod(am) && am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
if (am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
} else {
return null;
}
return new StdKeyDeserializer(kind, raw);
}
@Override
public Object deserializeKey(String key, DeserializationContext ctxt)
throws IOException
{
if (key == null) { // is this even legal call?
return null;
}
try {
Object result = _parse(key, ctxt);
if (result != null) {
return result;
}
} catch (Exception re) {
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: %s", re.getMessage());
<CHANGEE>
}
if (_keyClass.isEnum() && ctxt.getConfig().isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
return null;
}
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation");
}
public Class<?> getKeyClass() { return _keyClass; }
protected Object _parse(String key, DeserializationContext ctxt) throws Exception
{
switch (_kind) {
case TYPE_BOOLEAN:
if ("true".equals(key)) {
<FILEE>
<FILEB>
*/
if (ac.getParameterCount() == 1) {
Class<?> actArg = ac.getRawParameterType(0);
for (Class<?> expArg : argTypes) {
if (expArg == actArg) {
return ac.getAnnotated();
}
}
}
}
return null;
}
@Override
public Method findFactoryMethod(Class<?>... expArgTypes)
{
// So, of all single-arg static methods:
for (AnnotatedMethod am : _classInfo.getStaticMethods()) {
// 24-Oct-2016, tatu: Better ensure it only takes 1 arg, no matter what
<CHANGES>
if (isFactoryMethod(am)) {
<CHANGEE>
// And must take one of expected arg types (or supertype)
Class<?> actualArgType = am.getRawParameterType(0);
for (Class<?> expArgType : expArgTypes) {
// And one that matches what we would pass in
if (actualArgType.isAssignableFrom(expArgType)) {
return am.getAnnotated();
}
}
}
}
return null;
}
{
/* First: return<SCANS>Overrides;
_serializationConfig = new SerializationConfig(base,
_subtypeResolver, mixins, rootNames, propOverrides);
_deserializationConfig = new DeserializationConfig(base,
_subtypeResolver, mixins, rootNames, propOverrides);
// Some overrides we may need
final boolean needOrder = _jsonFactory.requiresPropertyOrdering();
if (needOrder ^ _serializationConfig.isEnabled(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY)) {
configure(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY, needOrder);
}
_serializerProvider = (sp == null) ? new DefaultSerializerProvider.Impl() : sp;
_deserializationContext = (dc == null) ?
new DefaultDeserializationContext.Impl(BeanDeserializerFactory.instance) : dc;
// Default serializer factory is stateless, can just assign
_serializerFactory = BeanSerializerFactory.instance;
}
/**
* Overridable helper method used to construct default {@link ClassIntrospector}
* to use.
*
* @since 2.5
*/
protected ClassIntrospector defaultClassIntrospector() {
return new BasicClassIntrospector();
}
/*
/**********************************************************
/* Methods sub-classes MUST override
/**********************************************************
*/
/**
* Method for creating a new {@link ObjectMapper} instance that
* has same initial configuration as this instance. Note that this
* also requires making a copy of the underlying {@link JsonFactory}
* instance.
*<p>
* Method is typically
* used when multiple, differently configured mappers are needed.
* Although configuration is shared, cached serializers and deserializers
* are NOT shared, which means that the new instance may be re-configured
* before use; meaning that it behaves the same way as if an instance
* was constructed from scratch.
*
* @since 2.1
*/
public ObjectMapper copy() {
_checkInvalidCopy(ObjectMapper.class);
return new ObjectMapper(this);
}
/**
* @since 2.1
*/
protected void _checkInvalidCopy(Class<?> exp)
{
if (getClass() != exp) {
throw new IllegalStateException("Failed copy(): "+getClass().getName()
+" (version: "+version()+") does not override copy(); it has to");
}
}
/*
/
JacksonDatabind, 65
<FILEB>
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: (%s) %s",
re.getClass().getName(), re.getMessage());
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
if (isFactoryMethod(am) && am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
if (am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
} else {
return null;
}
return new StdKeyDeserializer(kind, raw);
}
@Override
public Object deserializeKey(String key, DeserializationContext ctxt)
throws IOException
{
if (key == null) { // is this even legal call?
return null;
}
try {
Object result = _parse(key, ctxt);
if (result != null) {
return result;
}
} catch (Exception re) {
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: %s", re.getMessage());
<CHANGEE>
}
if (_keyClass.isEnum() && ctxt.getConfig().isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
return null;
}
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation");
}
public Class<?> getKeyClass() { return _keyClass; }
protected Object _parse(String key, DeserializationContext ctxt) throws Exception
{
switch (_kind) {
case TYPE_BOOLEAN:
if ("true".equals(key)) {
<FILEE>
<FILEB>
*/
if (ac.getParameterCount() == 1) {
Class<?> actArg = ac.getRawParameterType(0);
for (Class<?> expArg : argTypes) {
if (expArg == actArg) {
return ac.getAnnotated();
}
}
}
}
return null;
}
@Override
public Method findFactoryMethod(Class<?>... expArgTypes)
{
// So, of all single-arg static methods:
for (AnnotatedMethod am : _classInfo.getStaticMethods()) {
// 24-Oct-2016, tatu: Better ensure it only takes 1 arg, no matter what
<CHANGES>
if (isFactoryMethod(am)) {
<CHANGEE>
// And must take one of expected arg types (or supertype)
Class<?> actualArgType = am.getRawParameterType(0);
for (Class<?> expArgType : expArgTypes) {
// And one that matches what we would pass in
if (actualArgType.isAssignableFrom(expArgType)) {
return am.getAnnotated();
}
}
}
}
return null;
}
{
/* First: return<SCANS> that will bind data given JSON tree
* contains into specific value (usually bean) type.
*<p>
* Functionally equivalent to:
*<pre>
* objectMapper.convertValue(n, valueClass);
*</pre>
*/
@SuppressWarnings("unchecked")
@Override
public <T> T treeToValue(TreeNode n, Class<T> valueType)
throws JsonProcessingException
{
try {
// Simple cast when we just want to cast to, say, ObjectNode
// ... one caveat; while everything is Object.class, let's not take shortcut
if (valueType != Object.class && valueType.isAssignableFrom(n.getClass())) {
return (T) n;
}
// 20-Apr-2016, tatu: Another thing: for VALUE_EMBEDDED_OBJECT, assume similar
// short-cut coercion
if (n.asToken() == JsonToken.VALUE_EMBEDDED_OBJECT) {
if (n instanceof POJONode) {
Object ob = ((POJONode) n).getPojo();
if ((ob == null) || valueType.isInstance(ob)) {
return (T) ob;
}
}
}
return readValue(treeAsTokens(n), valueType);
} catch (JsonProcessingException e) {
throw e;
} catch (IOException e) { // should not occur, no real i/o...
throw new IllegalArgumentException(e.getMessage(), e);
}
}
/**
* Reverse of {@link #treeToValue}; given a value (usually bean), will
* construct equivalent JSON Tree representation. Functionally similar
* to serializing value into JSON and parsing JSON as tree, but
* more efficient.
*<p>
* NOTE: while results are usually identical to that of serialization followed
* by deserialization, this is not always the case. In some cases serialization
* into intermediate representation will retain encapsulation of things like
* raw value ({@link com.fasterxml.jackson.databind.util.RawValue}) or basic
* node identity ({@link JsonNode}). If so, result is a valid tree, but values
* are not re-constructed through actual JSON representation. So if transformation
* requires actual materialization of JSON (or other data format that this
JacksonDatabind, 65
<FILEB>
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: (%s) %s",
re.getClass().getName(), re.getMessage());
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
if (isFactoryMethod(am) && am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
if (am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
} else {
return null;
}
return new StdKeyDeserializer(kind, raw);
}
@Override
public Object deserializeKey(String key, DeserializationContext ctxt)
throws IOException
{
if (key == null) { // is this even legal call?
return null;
}
try {
Object result = _parse(key, ctxt);
if (result != null) {
return result;
}
} catch (Exception re) {
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: %s", re.getMessage());
<CHANGEE>
}
if (_keyClass.isEnum() && ctxt.getConfig().isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
return null;
}
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation");
}
public Class<?> getKeyClass() { return _keyClass; }
protected Object _parse(String key, DeserializationContext ctxt) throws Exception
{
switch (_kind) {
case TYPE_BOOLEAN:
if ("true".equals(key)) {
<FILEE>
<FILEB>
*/
if (ac.getParameterCount() == 1) {
Class<?> actArg = ac.getRawParameterType(0);
for (Class<?> expArg : argTypes) {
if (expArg == actArg) {
return ac.getAnnotated();
}
}
}
}
return null;
}
@Override
public Method findFactoryMethod(Class<?>... expArgTypes)
{
// So, of all single-arg static methods:
for (AnnotatedMethod am : _classInfo.getStaticMethods()) {
// 24-Oct-2016, tatu: Better ensure it only takes 1 arg, no matter what
<CHANGES>
if (isFactoryMethod(am)) {
<CHANGEE>
// And must take one of expected arg types (or supertype)
Class<?> actualArgType = am.getRawParameterType(0);
for (Class<?> expArgType : expArgTypes) {
// And one that matches what we would pass in
if (actualArgType.isAssignableFrom(expArgType)) {
return am.getAnnotated();
}
}
}
}
return null;
}
{
/* First: return<SCANS>Type == null) ? null : _typeFactory.constructType(rootType)),
/*PrettyPrinter*/null);
}
/**
* @deprecated Since 2.5, use {@link #writerFor(JavaType)} instead
*/
@Deprecated
public ObjectWriter writerWithType(JavaType rootType) {
return _newWriter(getSerializationConfig(), rootType, /*PrettyPrinter*/null);
}
/*
/**********************************************************
/* Extended Public API: constructing ObjectReaders
/* for more advanced configuration
/**********************************************************
*/
/**
* Factory method for constructing {@link ObjectReader} with
* default settings. Note that the resulting instance is NOT usable as is,
* without defining expected value type.
*/
public ObjectReader reader() {
return _newReader(getDeserializationConfig()).with(_injectableValues);
}
/**
* Factory method for constructing {@link ObjectReader} with
* specified feature enabled (compared to settings that this
* mapper instance has).
* Note that the resulting instance is NOT usable as is,
* without defining expected value type.
*/
public ObjectReader reader(DeserializationFeature feature) {
return _newReader(getDeserializationConfig().with(feature));
}
/**
* Factory method for constructing {@link ObjectReader} with
* specified features enabled (compared to settings that this
* mapper instance has).
* Note that the resulting instance is NOT usable as is,
* without defining expected value type.
*/
public ObjectReader reader(DeserializationFeature first,
DeserializationFeature... other) {
return _newReader(getDeserializationConfig().with(first, other));
}
/**
* Factory method for constructing {@link ObjectReader} that will
* update given Object (usually Bean, but can be a Collection or Map
* as well, but NOT an array) with JSON data. Deserialization occurs
* normally except that the root-level value in JSON is not used for
* instantiating a new object; instead give updateable object is used
* as root.
* Runtime type of value object is used for locating deserializer,
* unless overridden by other factory methods of {@link ObjectReader}
*/
public ObjectReader readerForUpdating(Object valueToUpdate) {
JavaType t = _typeFactory.constructType(valueToUpdate.getClass());
return _newReader(getDeserializationConfig(), t,
JacksonDatabind, 65
<FILEB>
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: (%s) %s",
re.getClass().getName(), re.getMessage());
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
if (isFactoryMethod(am) && am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
if (am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
} else {
return null;
}
return new StdKeyDeserializer(kind, raw);
}
@Override
public Object deserializeKey(String key, DeserializationContext ctxt)
throws IOException
{
if (key == null) { // is this even legal call?
return null;
}
try {
Object result = _parse(key, ctxt);
if (result != null) {
return result;
}
} catch (Exception re) {
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: %s", re.getMessage());
<CHANGEE>
}
if (_keyClass.isEnum() && ctxt.getConfig().isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
return null;
}
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation");
}
public Class<?> getKeyClass() { return _keyClass; }
protected Object _parse(String key, DeserializationContext ctxt) throws Exception
{
switch (_kind) {
case TYPE_BOOLEAN:
if ("true".equals(key)) {
<FILEE>
<FILEB>
*/
if (ac.getParameterCount() == 1) {
Class<?> actArg = ac.getRawParameterType(0);
for (Class<?> expArg : argTypes) {
if (expArg == actArg) {
return ac.getAnnotated();
}
}
}
}
return null;
}
@Override
public Method findFactoryMethod(Class<?>... expArgTypes)
{
// So, of all single-arg static methods:
for (AnnotatedMethod am : _classInfo.getStaticMethods()) {
// 24-Oct-2016, tatu: Better ensure it only takes 1 arg, no matter what
<CHANGES>
if (isFactoryMethod(am)) {
<CHANGEE>
// And must take one of expected arg types (or supertype)
Class<?> actualArgType = am.getRawParameterType(0);
for (Class<?> expArgType : expArgTypes) {
// And one that matches what we would pass in
if (actualArgType.isAssignableFrom(expArgType)) {
return am.getAnnotated();
}
}
}
}
return null;
}
{
/* First: return<SCANS> */
@SuppressWarnings("resource")
protected Object _convert(Object fromValue, JavaType toValueType)
throws IllegalArgumentException
{
// also, as per [databind#11], consider case for simple cast
/* But with caveats: one is that while everything is Object.class, we don't
* want to "optimize" that out; and the other is that we also do not want
* to lose conversions of generic types.
*/
Class<?> targetType = toValueType.getRawClass();
if (targetType != Object.class
&& !toValueType.hasGenericTypes()
&& targetType.isAssignableFrom(fromValue.getClass())) {
return fromValue;
}
// Then use TokenBuffer, which is a JsonGenerator:
TokenBuffer buf = new TokenBuffer(this, false);
if (isEnabled(DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS)) {
buf = buf.forceUseOfBigDecimal(true);
}
try {
// inlined 'writeValue' with minor changes:
// first: disable wrapping when writing
SerializationConfig config = getSerializationConfig().without(SerializationFeature.WRAP_ROOT_VALUE);
// no need to check for closing of TokenBuffer
_serializerProvider(config).serializeValue(buf, fromValue);
// then matching read, inlined 'readValue' with minor mods:
final JsonParser p = buf.asParser();
Object result;
// ok to pass in existing feature flags; unwrapping handled by mapper
final DeserializationConfig deserConfig = getDeserializationConfig();
JsonToken t = _initForReading(p);
if (t == JsonToken.VALUE_NULL) {
DeserializationContext ctxt = createDeserializationContext(p, deserConfig);
result = _findRootDeserializer(ctxt, toValueType).getNullValue(ctxt);
} else if (t == JsonToken.END_ARRAY || t == JsonToken.END_OBJECT) {
result = null;
} else { // pointing to event other than null
DeserializationContext ctxt = createDeserializationContext(p, deserConfig);
JsonDeserializer<Object> deser = _findRootDeserializer(ctxt, toValueType);
// note: no handling of unwrapping
result = deser.deserialize(p, ctxt);
}
p.close();
return result;
} catch (IOException e) { // should not occur, no real i
JacksonDatabind, 65
<FILEB>
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: (%s) %s",
re.getClass().getName(), re.getMessage());
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
if (isFactoryMethod(am) && am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
if (am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
} else {
return null;
}
return new StdKeyDeserializer(kind, raw);
}
@Override
public Object deserializeKey(String key, DeserializationContext ctxt)
throws IOException
{
if (key == null) { // is this even legal call?
return null;
}
try {
Object result = _parse(key, ctxt);
if (result != null) {
return result;
}
} catch (Exception re) {
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: %s", re.getMessage());
<CHANGEE>
}
if (_keyClass.isEnum() && ctxt.getConfig().isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
return null;
}
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation");
}
public Class<?> getKeyClass() { return _keyClass; }
protected Object _parse(String key, DeserializationContext ctxt) throws Exception
{
switch (_kind) {
case TYPE_BOOLEAN:
if ("true".equals(key)) {
<FILEE>
<FILEB>
*/
if (ac.getParameterCount() == 1) {
Class<?> actArg = ac.getRawParameterType(0);
for (Class<?> expArg : argTypes) {
if (expArg == actArg) {
return ac.getAnnotated();
}
}
}
}
return null;
}
@Override
public Method findFactoryMethod(Class<?>... expArgTypes)
{
// So, of all single-arg static methods:
for (AnnotatedMethod am : _classInfo.getStaticMethods()) {
// 24-Oct-2016, tatu: Better ensure it only takes 1 arg, no matter what
<CHANGES>
if (isFactoryMethod(am)) {
<CHANGEE>
// And must take one of expected arg types (or supertype)
Class<?> actualArgType = am.getRawParameterType(0);
for (Class<?> expArgType : expArgTypes) {
// And one that matches what we would pass in
if (actualArgType.isAssignableFrom(expArgType)) {
return am.getAnnotated();
}
}
}
}
return null;
}
{
/* First: return<SCANS>
if (deser != null) {
return deser;
}
// Nope: need to ask provider to resolve it
deser = ctxt.findRootValueDeserializer(valueType);
if (deser == null) { // can this happen?
throw JsonMappingException.from(ctxt,
"Can not find a deserializer for type "+valueType);
}
_rootDeserializers.put(valueType, deser);
return deser;
}
/**
* @since 2.2
*/
protected void _verifySchemaType(FormatSchema schema)
{
if (schema != null) {
if (!_jsonFactory.canUseSchema(schema)) {
throw new IllegalArgumentException("Can not use FormatSchema of type "+schema.getClass().getName()
+" for format "+_jsonFactory.getFormatName());
}
}
}
}
JacksonDatabind, 65
<FILEB>
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: (%s) %s",
re.getClass().getName(), re.getMessage());
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
if (isFactoryMethod(am) && am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
if (am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
} else {
return null;
}
return new StdKeyDeserializer(kind, raw);
}
@Override
public Object deserializeKey(String key, DeserializationContext ctxt)
throws IOException
{
if (key == null) { // is this even legal call?
return null;
}
try {
Object result = _parse(key, ctxt);
if (result != null) {
return result;
}
} catch (Exception re) {
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: %s", re.getMessage());
<CHANGEE>
}
if (_keyClass.isEnum() && ctxt.getConfig().isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
return null;
}
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation");
}
public Class<?> getKeyClass() { return _keyClass; }
protected Object _parse(String key, DeserializationContext ctxt) throws Exception
{
switch (_kind) {
case TYPE_BOOLEAN:
if ("true".equals(key)) {
<FILEE>
<FILEB>
*/
if (ac.getParameterCount() == 1) {
Class<?> actArg = ac.getRawParameterType(0);
for (Class<?> expArg : argTypes) {
if (expArg == actArg) {
return ac.getAnnotated();
}
}
}
}
return null;
}
@Override
public Method findFactoryMethod(Class<?>... expArgTypes)
{
// So, of all single-arg static methods:
for (AnnotatedMethod am : _classInfo.getStaticMethods()) {
// 24-Oct-2016, tatu: Better ensure it only takes 1 arg, no matter what
<CHANGES>
if (isFactoryMethod(am)) {
<CHANGEE>
// And must take one of expected arg types (or supertype)
Class<?> actualArgType = am.getRawParameterType(0);
for (Class<?> expArgType : expArgTypes) {
// And one that matches what we would pass in
if (actualArgType.isAssignableFrom(expArgType)) {
return am.getAnnotated();
}
}
}
}
return null;
}
{
/* First: return<SCANS> public JacksonAnnotationIntrospector setConstructorPropertiesImpliesCreator(boolean b)
{
_cfgConstructorPropertiesImpliesCreator = b;
return this;
}
/*
/**********************************************************
/* General annotation properties
/**********************************************************
*/
/**
* Annotations with meta-annotation {@link JacksonAnnotationsInside}
* are considered bundles.
*/
@Override
public boolean isAnnotationBundle(Annotation ann) {
// 22-Sep-2015, tatu: Caching here has modest effect on JavaSE, and only
// mostly in degenerate cases where introspection used more often than
// it should (like recreating ObjectMapper once per read/write).
// But it may be more beneficial on platforms like Android (should verify)
Class<?> type = ann.annotationType();
Boolean b = _annotationsInside.get(type);
if (b == null) {
b = type.getAnnotation(JacksonAnnotationsInside.class) != null;
_annotationsInside.putIfAbsent(type, b);
}
return b.booleanValue();
}
/*
/**********************************************************
/* General annotations
/**********************************************************
*/
/**
* Since 2.6, we have supported use of {@link JsonProperty} for specifying
* explicit serialized name
*/
@Override
@Deprecated
public String findEnumValue(Enum<?> value)
{
// 11-Jun-2015, tatu: As per [databind#677], need to allow explicit naming.
// Unfortunately can not quite use standard AnnotatedClass here (due to various
// reasons, including odd representation JVM uses); has to do for now
try {
// We know that values are actually static fields with matching name so:
Field f = value.getClass().getField(value.name());
if (f != null) {
JsonProperty prop = f.getAnnotation(JsonProperty.class);
if (prop != null) {
String n = prop.value();
if (n != null && !n.isEmpty()) {
return n;
}
}
}
} catch (SecurityException e) {
// 17-Sep-2015, tatu: Anything we could/should do here?
} catch (NoSuchFieldException e) {
// 1
JacksonDatabind, 65
<FILEB>
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: (%s) %s",
re.getClass().getName(), re.getMessage());
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
if (isFactoryMethod(am) && am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
if (am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
} else {
return null;
}
return new StdKeyDeserializer(kind, raw);
}
@Override
public Object deserializeKey(String key, DeserializationContext ctxt)
throws IOException
{
if (key == null) { // is this even legal call?
return null;
}
try {
Object result = _parse(key, ctxt);
if (result != null) {
return result;
}
} catch (Exception re) {
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: %s", re.getMessage());
<CHANGEE>
}
if (_keyClass.isEnum() && ctxt.getConfig().isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
return null;
}
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation");
}
public Class<?> getKeyClass() { return _keyClass; }
protected Object _parse(String key, DeserializationContext ctxt) throws Exception
{
switch (_kind) {
case TYPE_BOOLEAN:
if ("true".equals(key)) {
<FILEE>
<FILEB>
*/
if (ac.getParameterCount() == 1) {
Class<?> actArg = ac.getRawParameterType(0);
for (Class<?> expArg : argTypes) {
if (expArg == actArg) {
return ac.getAnnotated();
}
}
}
}
return null;
}
@Override
public Method findFactoryMethod(Class<?>... expArgTypes)
{
// So, of all single-arg static methods:
for (AnnotatedMethod am : _classInfo.getStaticMethods()) {
// 24-Oct-2016, tatu: Better ensure it only takes 1 arg, no matter what
<CHANGES>
if (isFactoryMethod(am)) {
<CHANGEE>
// And must take one of expected arg types (or supertype)
Class<?> actualArgType = am.getRawParameterType(0);
for (Class<?> expArgType : expArgTypes) {
// And one that matches what we would pass in
if (actualArgType.isAssignableFrom(expArgType)) {
return am.getAnnotated();
}
}
}
}
return null;
}
{
/* First: return<SCANS>(Class<?> keyClass, String keyValue,
String msg, Object... msgArgs)
throws IOException
{
// but if not handled, just throw exception
if (msgArgs.length > 0) {
msg = String.format(msg, msgArgs);
}
LinkedNode<DeserializationProblemHandler> h = _config.getProblemHandlers();
while (h != null) {
// Can bail out if it's handled
Object key = h.value().handleWeirdKey(this, keyClass, keyValue, msg);
if (key != DeserializationProblemHandler.NOT_HANDLED) {
// Sanity check for broken handlers, otherwise nasty to debug:
if ((key == null) || keyClass.isInstance(key)) {
return key;
}
throw weirdStringException(keyValue, keyClass, String.format(
"DeserializationProblemHandler.handleWeirdStringValue() for type %s returned value of type %s",
keyClass, key.getClass()));
}
h = h.next();
}
throw weirdKeyException(keyClass, keyValue, msg);
}
/**
* Method that deserializers should call if they encounter a String value
* that can not be converted to target property type, in cases where some
* String values could be acceptable (either with different settings,
* or different value).
* Default implementation will try to call {@link DeserializationProblemHandler#handleWeirdStringValue}
* on configured handlers, if any, to allow for recovery; if recovery does not
* succeed, will throw {@link InvalidFormatException} with given message.
*
* @param targetClass Type of property into which incoming number should be converted
* @param value String value from which to deserialize property value
* @param msg Error message template caller wants to use if exception is to be thrown
* @param msgArgs Optional arguments to use for message, if any
*
* @return Property value to use
*
* @throws IOException To indicate unrecoverable problem, usually based on <code>msg</code>
*
* @since 2.8
*/
public Object handleWeirdStringValue(Class<?> targetClass, String value,
String msg, Object... msgArgs)
throws IOException
{
// but if not handled, just throw exception
if (msgArgs.length > 0)
JacksonDatabind, 65
<FILEB>
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: (%s) %s",
re.getClass().getName(), re.getMessage());
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
if (isFactoryMethod(am) && am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
if (am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
} else {
return null;
}
return new StdKeyDeserializer(kind, raw);
}
@Override
public Object deserializeKey(String key, DeserializationContext ctxt)
throws IOException
{
if (key == null) { // is this even legal call?
return null;
}
try {
Object result = _parse(key, ctxt);
if (result != null) {
return result;
}
} catch (Exception re) {
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: %s", re.getMessage());
<CHANGEE>
}
if (_keyClass.isEnum() && ctxt.getConfig().isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
return null;
}
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation");
}
public Class<?> getKeyClass() { return _keyClass; }
protected Object _parse(String key, DeserializationContext ctxt) throws Exception
{
switch (_kind) {
case TYPE_BOOLEAN:
if ("true".equals(key)) {
<FILEE>
<FILEB>
*/
if (ac.getParameterCount() == 1) {
Class<?> actArg = ac.getRawParameterType(0);
for (Class<?> expArg : argTypes) {
if (expArg == actArg) {
return ac.getAnnotated();
}
}
}
}
return null;
}
@Override
public Method findFactoryMethod(Class<?>... expArgTypes)
{
// So, of all single-arg static methods:
for (AnnotatedMethod am : _classInfo.getStaticMethods()) {
// 24-Oct-2016, tatu: Better ensure it only takes 1 arg, no matter what
<CHANGES>
if (isFactoryMethod(am)) {
<CHANGEE>
// And must take one of expected arg types (or supertype)
Class<?> actualArgType = am.getRawParameterType(0);
for (Class<?> expArgType : expArgTypes) {
// And one that matches what we would pass in
if (actualArgType.isAssignableFrom(expArgType)) {
return am.getAnnotated();
}
}
}
}
return null;
}
{
/* First: return<SCANS> {
msg = String.format(msg, msgArgs);
}
LinkedNode<DeserializationProblemHandler> h = _config.getProblemHandlers();
while (h != null) {
// Can bail out if it's handled
Object instance = h.value().handleWeirdStringValue(this, targetClass, value, msg);
if (instance != DeserializationProblemHandler.NOT_HANDLED) {
// Sanity check for broken handlers, otherwise nasty to debug:
if ((instance == null) || targetClass.isInstance(instance)) {
return instance;
}
throw weirdStringException(value, targetClass, String.format(
"DeserializationProblemHandler.handleWeirdStringValue() for type %s returned value of type %s",
targetClass, instance.getClass()));
}
h = h.next();
}
throw weirdStringException(value, targetClass, msg);
}
/**
* Method that deserializers should call if they encounter a numeric value
* that can not be converted to target property type, in cases where some
* numeric values could be acceptable (either with different settings,
* or different numeric value).
* Default implementation will try to call {@link DeserializationProblemHandler#handleWeirdNumberValue}
* on configured handlers, if any, to allow for recovery; if recovery does not
* succeed, will throw {@link InvalidFormatException} with given message.
*
* @param targetClass Type of property into which incoming number should be converted
* @param value Number value from which to deserialize property value
* @param msg Error message template caller wants to use if exception is to be thrown
* @param msgArgs Optional arguments to use for message, if any
*
* @return Property value to use
*
* @throws IOException To indicate unrecoverable problem, usually based on <code>msg</code>
*
* @since 2.8
*/
public Object handleWeirdNumberValue(Class<?> targetClass, Number value,
String msg, Object... msgArgs)
throws IOException
{
if (msgArgs.length > 0) {
msg = String.format(msg, msgArgs);
}
LinkedNode<DeserializationProblemHandler> h = _config.getProblemHandlers();
while (h != null) {
// Can bail out if it's handled
Object key = h.
JacksonDatabind, 65
<FILEB>
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: (%s) %s",
re.getClass().getName(), re.getMessage());
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
if (isFactoryMethod(am) && am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
if (am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
} else {
return null;
}
return new StdKeyDeserializer(kind, raw);
}
@Override
public Object deserializeKey(String key, DeserializationContext ctxt)
throws IOException
{
if (key == null) { // is this even legal call?
return null;
}
try {
Object result = _parse(key, ctxt);
if (result != null) {
return result;
}
} catch (Exception re) {
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: %s", re.getMessage());
<CHANGEE>
}
if (_keyClass.isEnum() && ctxt.getConfig().isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
return null;
}
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation");
}
public Class<?> getKeyClass() { return _keyClass; }
protected Object _parse(String key, DeserializationContext ctxt) throws Exception
{
switch (_kind) {
case TYPE_BOOLEAN:
if ("true".equals(key)) {
<FILEE>
<FILEB>
*/
if (ac.getParameterCount() == 1) {
Class<?> actArg = ac.getRawParameterType(0);
for (Class<?> expArg : argTypes) {
if (expArg == actArg) {
return ac.getAnnotated();
}
}
}
}
return null;
}
@Override
public Method findFactoryMethod(Class<?>... expArgTypes)
{
// So, of all single-arg static methods:
for (AnnotatedMethod am : _classInfo.getStaticMethods()) {
// 24-Oct-2016, tatu: Better ensure it only takes 1 arg, no matter what
<CHANGES>
if (isFactoryMethod(am)) {
<CHANGEE>
// And must take one of expected arg types (or supertype)
Class<?> actualArgType = am.getRawParameterType(0);
for (Class<?> expArgType : expArgTypes) {
// And one that matches what we would pass in
if (actualArgType.isAssignableFrom(expArgType)) {
return am.getAnnotated();
}
}
}
}
return null;
}
{
/* First: return<SCANS>value().handleWeirdNumberValue(this, targetClass, value, msg);
if (key != DeserializationProblemHandler.NOT_HANDLED) {
// Sanity check for broken handlers, otherwise nasty to debug:
if ((key == null) || targetClass.isInstance(key)) {
return key;
}
throw weirdNumberException(value, targetClass, String.format(
"DeserializationProblemHandler.handleWeirdNumberValue() for type %s returned value of type %s",
targetClass, key.getClass()));
}
h = h.next();
}
throw weirdNumberException(value, targetClass, msg);
}
/**
* Method that deserializers should call if they fail to instantiate value
* due to lack of viable instantiator (usually creator, that is, constructor
* or static factory method). Method should be called at point where value
* has not been decoded, so that handler has a chance to handle decoding
* using alternate mechanism, and handle underlying content (possibly by
* just skipping it) to keep input state valid
*
* @param instClass Type that was to be instantiated
* @param p Parser that points to the JSON value to decode
*
* @return Object that should be constructed, if any; has to be of type <code>instClass</code>
*
* @since 2.8
*/
public Object handleMissingInstantiator(Class<?> instClass, JsonParser p,
String msg, Object... msgArgs)
throws IOException
{
if (msgArgs.length > 0) {
msg = String.format(msg, msgArgs);
}
LinkedNode<DeserializationProblemHandler> h = _config.getProblemHandlers();
while (h != null) {
// Can bail out if it's handled
Object instance = h.value().handleMissingInstantiator(this,
instClass, p, msg);
if (instance != DeserializationProblemHandler.NOT_HANDLED) {
// Sanity check for broken handlers, otherwise nasty to debug:
if ((instance == null) || instClass.isInstance(instance)) {
return instance;
}
throw instantiationException(instClass, String.format(
"DeserializationProblemHandler.handleMissingInstantiator() for type %s returned value of type %s",
instClass, instance.getClass
JacksonDatabind, 65
<FILEB>
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: (%s) %s",
re.getClass().getName(), re.getMessage());
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
if (isFactoryMethod(am) && am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
if (am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
} else {
return null;
}
return new StdKeyDeserializer(kind, raw);
}
@Override
public Object deserializeKey(String key, DeserializationContext ctxt)
throws IOException
{
if (key == null) { // is this even legal call?
return null;
}
try {
Object result = _parse(key, ctxt);
if (result != null) {
return result;
}
} catch (Exception re) {
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: %s", re.getMessage());
<CHANGEE>
}
if (_keyClass.isEnum() && ctxt.getConfig().isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
return null;
}
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation");
}
public Class<?> getKeyClass() { return _keyClass; }
protected Object _parse(String key, DeserializationContext ctxt) throws Exception
{
switch (_kind) {
case TYPE_BOOLEAN:
if ("true".equals(key)) {
<FILEE>
<FILEB>
*/
if (ac.getParameterCount() == 1) {
Class<?> actArg = ac.getRawParameterType(0);
for (Class<?> expArg : argTypes) {
if (expArg == actArg) {
return ac.getAnnotated();
}
}
}
}
return null;
}
@Override
public Method findFactoryMethod(Class<?>... expArgTypes)
{
// So, of all single-arg static methods:
for (AnnotatedMethod am : _classInfo.getStaticMethods()) {
// 24-Oct-2016, tatu: Better ensure it only takes 1 arg, no matter what
<CHANGES>
if (isFactoryMethod(am)) {
<CHANGEE>
// And must take one of expected arg types (or supertype)
Class<?> actualArgType = am.getRawParameterType(0);
for (Class<?> expArgType : expArgTypes) {
// And one that matches what we would pass in
if (actualArgType.isAssignableFrom(expArgType)) {
return am.getAnnotated();
}
}
}
}
return null;
}
{
/* First: return<SCANS>()));
}
h = h.next();
}
throw instantiationException(instClass, msg);
}
/**
* Method that deserializers should call if they fail to instantiate value
* due to an exception that was thrown by constructor (or other mechanism used
* to create instances).
* Default implementation will try to call {@link DeserializationProblemHandler#handleInstantiationProblem}
* on configured handlers, if any, to allow for recovery; if recovery does not
* succeed, will throw exception constructed with {@link #instantiationException}.
*
* @param instClass Type that was to be instantiated
* @param argument (optional) Argument that was passed to constructor or equivalent
* instantiator; often a {@link java.lang.String}.
* @param t Exception that caused failure
*
* @return Object that should be constructed, if any; has to be of type <code>instClass</code>
*
* @since 2.8
*/
public Object handleInstantiationProblem(Class<?> instClass, Object argument,
Throwable t)
throws IOException
{
LinkedNode<DeserializationProblemHandler> h = _config.getProblemHandlers();
while (h != null) {
// Can bail out if it's handled
Object instance = h.value().handleInstantiationProblem(this, instClass, argument, t);
if (instance != DeserializationProblemHandler.NOT_HANDLED) {
// Sanity check for broken handlers, otherwise nasty to debug:
if ((instance == null) || instClass.isInstance(instance)) {
return instance;
}
throw instantiationException(instClass, String.format(
"DeserializationProblemHandler.handleInstantiationProblem() for type %s returned value of type %s",
instClass, instance.getClass()));
}
h = h.next();
}
// 18-May-2016, tatu: Only wrap if not already a valid type to throw
if (t instanceof IOException) {
throw (IOException) t;
}
throw instantiationException(instClass, t);
}
/**
* Method that deserializers should call if the first token of the value to
* deserialize is of unexpected type (that is, type of token that deserializer
* can not handle). This could occur, for example, if a Number deserializer
* encounter {@link
JacksonDatabind, 65
<FILEB>
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: (%s) %s",
re.getClass().getName(), re.getMessage());
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
if (isFactoryMethod(am) && am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
if (am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
} else {
return null;
}
return new StdKeyDeserializer(kind, raw);
}
@Override
public Object deserializeKey(String key, DeserializationContext ctxt)
throws IOException
{
if (key == null) { // is this even legal call?
return null;
}
try {
Object result = _parse(key, ctxt);
if (result != null) {
return result;
}
} catch (Exception re) {
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: %s", re.getMessage());
<CHANGEE>
}
if (_keyClass.isEnum() && ctxt.getConfig().isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
return null;
}
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation");
}
public Class<?> getKeyClass() { return _keyClass; }
protected Object _parse(String key, DeserializationContext ctxt) throws Exception
{
switch (_kind) {
case TYPE_BOOLEAN:
if ("true".equals(key)) {
<FILEE>
<FILEB>
*/
if (ac.getParameterCount() == 1) {
Class<?> actArg = ac.getRawParameterType(0);
for (Class<?> expArg : argTypes) {
if (expArg == actArg) {
return ac.getAnnotated();
}
}
}
}
return null;
}
@Override
public Method findFactoryMethod(Class<?>... expArgTypes)
{
// So, of all single-arg static methods:
for (AnnotatedMethod am : _classInfo.getStaticMethods()) {
// 24-Oct-2016, tatu: Better ensure it only takes 1 arg, no matter what
<CHANGES>
if (isFactoryMethod(am)) {
<CHANGEE>
// And must take one of expected arg types (or supertype)
Class<?> actualArgType = am.getRawParameterType(0);
for (Class<?> expArgType : expArgTypes) {
// And one that matches what we would pass in
if (actualArgType.isAssignableFrom(expArgType)) {
return am.getAnnotated();
}
}
}
}
return null;
}
{
/* First: return<SCANS> JsonToken#START_ARRAY} instead of
* {@link JsonToken#VALUE_NUMBER_INT} or {@link JsonToken#VALUE_NUMBER_FLOAT}.
*
* @param instClass Type that was to be instantiated
* @param p Parser that points to the JSON value to decode
*
* @return Object that should be constructed, if any; has to be of type <code>instClass</code>
*
* @since 2.8
*/
public Object handleUnexpectedToken(Class<?> instClass, JsonParser p)
throws IOException
{
return handleUnexpectedToken(instClass, p.getCurrentToken(), p, null);
}
/**
* Method that deserializers should call if the first token of the value to
* deserialize is of unexpected type (that is, type of token that deserializer
* can not handle). This could occur, for example, if a Number deserializer
* encounter {@link JsonToken#START_ARRAY} instead of
* {@link JsonToken#VALUE_NUMBER_INT} or {@link JsonToken#VALUE_NUMBER_FLOAT}.
*
* @param instClass Type that was to be instantiated
* @param p Parser that points to the JSON value to decode
*
* @return Object that should be constructed, if any; has to be of type <code>instClass</code>
*
* @since 2.8
*/
public Object handleUnexpectedToken(Class<?> instClass, JsonToken t,
JsonParser p,
String msg, Object... msgArgs)
throws IOException
{
if (msgArgs.length > 0) {
msg = String.format(msg, msgArgs);
}
LinkedNode<DeserializationProblemHandler> h = _config.getProblemHandlers();
while (h != null) {
Object instance = h.value().handleUnexpectedToken(this,
instClass, t, p, msg);
if (instance != DeserializationProblemHandler.NOT_HANDLED) {
if ((instance == null) || instClass.isInstance(instance)) {
return instance;
}
reportMappingException("DeserializationProblemHandler.handleUnexpectedToken() for type %s returned value of type %s",
instClass, instance.getClass());
}
h = h.next();
}
if (msg == null) {
if (t == null
JacksonDatabind, 65
<FILEB>
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: (%s) %s",
re.getClass().getName(), re.getMessage());
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
if (isFactoryMethod(am) && am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
if (am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
} else {
return null;
}
return new StdKeyDeserializer(kind, raw);
}
@Override
public Object deserializeKey(String key, DeserializationContext ctxt)
throws IOException
{
if (key == null) { // is this even legal call?
return null;
}
try {
Object result = _parse(key, ctxt);
if (result != null) {
return result;
}
} catch (Exception re) {
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: %s", re.getMessage());
<CHANGEE>
}
if (_keyClass.isEnum() && ctxt.getConfig().isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
return null;
}
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation");
}
public Class<?> getKeyClass() { return _keyClass; }
protected Object _parse(String key, DeserializationContext ctxt) throws Exception
{
switch (_kind) {
case TYPE_BOOLEAN:
if ("true".equals(key)) {
<FILEE>
<FILEB>
*/
if (ac.getParameterCount() == 1) {
Class<?> actArg = ac.getRawParameterType(0);
for (Class<?> expArg : argTypes) {
if (expArg == actArg) {
return ac.getAnnotated();
}
}
}
}
return null;
}
@Override
public Method findFactoryMethod(Class<?>... expArgTypes)
{
// So, of all single-arg static methods:
for (AnnotatedMethod am : _classInfo.getStaticMethods()) {
// 24-Oct-2016, tatu: Better ensure it only takes 1 arg, no matter what
<CHANGES>
if (isFactoryMethod(am)) {
<CHANGEE>
// And must take one of expected arg types (or supertype)
Class<?> actualArgType = am.getRawParameterType(0);
for (Class<?> expArgType : expArgTypes) {
// And one that matches what we would pass in
if (actualArgType.isAssignableFrom(expArgType)) {
return am.getAnnotated();
}
}
}
}
return null;
}
{
/* First: return<SCANS>(msg, msgArgs);
}
throw JsonMappingException.from(getParser(), msg);
}
/**
* @since 2.8
*/
public void reportMissingContent(String msg, Object... msgArgs)
throws JsonMappingException
{
if (msg == null) {
msg = "No content to map due to end-of-input";
} else if (msgArgs.length > 0) {
msg = String.format(msg, msgArgs);
}
throw JsonMappingException.from(getParser(), msg);
}
/**
* @since 2.8
*/
public void reportUnresolvedObjectId(ObjectIdReader oidReader, Object bean)
throws JsonMappingException
{
String msg = String.format("No Object Id found for an instance of %s, to assign to property '%s'",
bean.getClass().getName(), oidReader.propertyName);
throw JsonMappingException.from(getParser(), msg);
}
/**
* Helper method called to indicate problem in POJO (serialization) definitions or settings
* regarding specific Java type, unrelated to actual JSON content to map.
* Default behavior is to construct and throw a {@link JsonMappingException}.
*
* @since 2.9
*/
public <T> T reportBadTypeDefinition(BeanDescription bean,
String message, Object... args) throws JsonMappingException {
if (args != null && args.length > 0) {
message = String.format(message, args);
}
String beanDesc = (bean == null) ? "N/A" : _desc(bean.getType().getGenericSignature());
throw mappingException("Invalid type definition for type %s: %s",
beanDesc, message);
}
/**
* Helper method called to indicate problem in POJO (serialization) definitions or settings
* regarding specific property (of a type), unrelated to actual JSON content to map.
* Default behavior is to construct and throw a {@link JsonMappingException}.
*
* @since 2.9
*/
public <T> T reportBadPropertyDefinition(BeanDescription bean, BeanPropertyDefinition prop,
String message, Object... args) throws JsonMappingException {
if (args != null && args.length > 0) {
message = String.format(message, args);
}
JacksonDatabind, 65
<FILEB>
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: (%s) %s",
re.getClass().getName(), re.getMessage());
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
if (isFactoryMethod(am) && am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
if (am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
} else {
return null;
}
return new StdKeyDeserializer(kind, raw);
}
@Override
public Object deserializeKey(String key, DeserializationContext ctxt)
throws IOException
{
if (key == null) { // is this even legal call?
return null;
}
try {
Object result = _parse(key, ctxt);
if (result != null) {
return result;
}
} catch (Exception re) {
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: %s", re.getMessage());
<CHANGEE>
}
if (_keyClass.isEnum() && ctxt.getConfig().isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
return null;
}
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation");
}
public Class<?> getKeyClass() { return _keyClass; }
protected Object _parse(String key, DeserializationContext ctxt) throws Exception
{
switch (_kind) {
case TYPE_BOOLEAN:
if ("true".equals(key)) {
<FILEE>
<FILEB>
*/
if (ac.getParameterCount() == 1) {
Class<?> actArg = ac.getRawParameterType(0);
for (Class<?> expArg : argTypes) {
if (expArg == actArg) {
return ac.getAnnotated();
}
}
}
}
return null;
}
@Override
public Method findFactoryMethod(Class<?>... expArgTypes)
{
// So, of all single-arg static methods:
for (AnnotatedMethod am : _classInfo.getStaticMethods()) {
// 24-Oct-2016, tatu: Better ensure it only takes 1 arg, no matter what
<CHANGES>
if (isFactoryMethod(am)) {
<CHANGEE>
// And must take one of expected arg types (or supertype)
Class<?> actualArgType = am.getRawParameterType(0);
for (Class<?> expArgType : expArgTypes) {
// And one that matches what we would pass in
if (actualArgType.isAssignableFrom(expArgType)) {
return am.getAnnotated();
}
}
}
}
return null;
}
{
/* First: return<SCANS> /***********************************************************
*/
/**
* Method called to access property that this bean stands for, from within
* given bean, and to serialize it as a JSON Object field using appropriate
* serializer.
*/
@Override
public void serializeAsField(Object bean, JsonGenerator gen,
SerializerProvider prov) throws Exception {
// inlined 'get()'
final Object value = (_accessorMethod == null) ? _field.get(bean)
: _accessorMethod.invoke(bean);
// Null handling is bit different, check that first
if (value == null) {
if (_nullSerializer != null) {
gen.writeFieldName(_name);
_nullSerializer.serialize(null, gen, prov);
}
return;
}
// then find serializer to use
JsonSerializer<Object> ser = _serializer;
if (ser == null) {
Class<?> cls = value.getClass();
PropertySerializerMap m = _dynamicSerializers;
ser = m.serializerFor(cls);
if (ser == null) {
ser = _findAndAddDynamic(m, cls, prov);
}
}
// and then see if we must suppress certain values (default, empty)
if (_suppressableValue != null) {
if (MARKER_FOR_EMPTY == _suppressableValue) {
if (ser.isEmpty(prov, value)) {
return;
}
} else if (_suppressableValue.equals(value)) {
return;
}
}
// For non-nulls: simple check for direct cycles
if (value == bean) {
// three choices: exception; handled by call; or pass-through
if (_handleSelfReference(bean, gen, prov, ser)) {
return;
}
}
gen.writeFieldName(_name);
if (_typeSerializer == null) {
ser.serialize(value, gen, prov);
} else {
ser.serializeWithType(value, gen, prov, _typeSerializer);
}
}
/**
* Method called to indicate that serialization of a field was omitted due
* to filtering, in cases where backend data format does not allow basic
* omission.
*
* @since 2.3
*/
@Override
public void serializeAsOmittedField(Object bean, JsonGenerator gen,
SerializerProvider prov) throws Exception {
JacksonDatabind, 65
<FILEB>
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: (%s) %s",
re.getClass().getName(), re.getMessage());
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
if (isFactoryMethod(am) && am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
if (am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
} else {
return null;
}
return new StdKeyDeserializer(kind, raw);
}
@Override
public Object deserializeKey(String key, DeserializationContext ctxt)
throws IOException
{
if (key == null) { // is this even legal call?
return null;
}
try {
Object result = _parse(key, ctxt);
if (result != null) {
return result;
}
} catch (Exception re) {
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: %s", re.getMessage());
<CHANGEE>
}
if (_keyClass.isEnum() && ctxt.getConfig().isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
return null;
}
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation");
}
public Class<?> getKeyClass() { return _keyClass; }
protected Object _parse(String key, DeserializationContext ctxt) throws Exception
{
switch (_kind) {
case TYPE_BOOLEAN:
if ("true".equals(key)) {
<FILEE>
<FILEB>
*/
if (ac.getParameterCount() == 1) {
Class<?> actArg = ac.getRawParameterType(0);
for (Class<?> expArg : argTypes) {
if (expArg == actArg) {
return ac.getAnnotated();
}
}
}
}
return null;
}
@Override
public Method findFactoryMethod(Class<?>... expArgTypes)
{
// So, of all single-arg static methods:
for (AnnotatedMethod am : _classInfo.getStaticMethods()) {
// 24-Oct-2016, tatu: Better ensure it only takes 1 arg, no matter what
<CHANGES>
if (isFactoryMethod(am)) {
<CHANGEE>
// And must take one of expected arg types (or supertype)
Class<?> actualArgType = am.getRawParameterType(0);
for (Class<?> expArgType : expArgTypes) {
// And one that matches what we would pass in
if (actualArgType.isAssignableFrom(expArgType)) {
return am.getAnnotated();
}
}
}
}
return null;
}
{
/* First: return<SCANS> if (!gen.canOmitFields()) {
gen.writeOmittedField(_name.getValue());
}
}
/**
* Alternative to {@link #serializeAsField} that is used when a POJO is
* serialized as JSON Array; the difference is that no field names are
* written.
*
* @since 2.3
*/
@Override
public void serializeAsElement(Object bean, JsonGenerator gen,
SerializerProvider prov) throws Exception {
// inlined 'get()'
final Object value = (_accessorMethod == null) ? _field.get(bean)
: _accessorMethod.invoke(bean);
if (value == null) { // nulls need specialized handling
if (_nullSerializer != null) {
_nullSerializer.serialize(null, gen, prov);
} else { // can NOT suppress entries in tabular output
gen.writeNull();
}
return;
}
// otherwise find serializer to use
JsonSerializer<Object> ser = _serializer;
if (ser == null) {
Class<?> cls = value.getClass();
PropertySerializerMap map = _dynamicSerializers;
ser = map.serializerFor(cls);
if (ser == null) {
ser = _findAndAddDynamic(map, cls, prov);
}
}
// and then see if we must suppress certain values (default, empty)
if (_suppressableValue != null) {
if (MARKER_FOR_EMPTY == _suppressableValue) {
if (ser.isEmpty(prov, value)) { // can NOT suppress entries in
// tabular output
serializeAsPlaceholder(bean, gen, prov);
return;
}
} else if (_suppressableValue.equals(value)) { // can NOT suppress
// entries in tabular
// output
serializeAsPlaceholder(bean, gen, prov);
return;
}
}
// For non-nulls: simple check for direct cycles
if (value == bean) {
if (_handleSelfReference(bean, gen, prov, ser)) {
return;
}
}
if (_typeSerializer == null) {
ser.serialize(value, gen, prov);
} else {
ser.serializeWithType(value, gen, prov, _typeSerializer);
}
}
/**
* Method called to serialize a placeholder used in
JacksonDatabind, 65
<FILEB>
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: (%s) %s",
re.getClass().getName(), re.getMessage());
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
if (isFactoryMethod(am) && am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
if (am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
} else {
return null;
}
return new StdKeyDeserializer(kind, raw);
}
@Override
public Object deserializeKey(String key, DeserializationContext ctxt)
throws IOException
{
if (key == null) { // is this even legal call?
return null;
}
try {
Object result = _parse(key, ctxt);
if (result != null) {
return result;
}
} catch (Exception re) {
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: %s", re.getMessage());
<CHANGEE>
}
if (_keyClass.isEnum() && ctxt.getConfig().isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
return null;
}
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation");
}
public Class<?> getKeyClass() { return _keyClass; }
protected Object _parse(String key, DeserializationContext ctxt) throws Exception
{
switch (_kind) {
case TYPE_BOOLEAN:
if ("true".equals(key)) {
<FILEE>
<FILEB>
*/
if (ac.getParameterCount() == 1) {
Class<?> actArg = ac.getRawParameterType(0);
for (Class<?> expArg : argTypes) {
if (expArg == actArg) {
return ac.getAnnotated();
}
}
}
}
return null;
}
@Override
public Method findFactoryMethod(Class<?>... expArgTypes)
{
// So, of all single-arg static methods:
for (AnnotatedMethod am : _classInfo.getStaticMethods()) {
// 24-Oct-2016, tatu: Better ensure it only takes 1 arg, no matter what
<CHANGES>
if (isFactoryMethod(am)) {
<CHANGEE>
// And must take one of expected arg types (or supertype)
Class<?> actualArgType = am.getRawParameterType(0);
for (Class<?> expArgType : expArgTypes) {
// And one that matches what we would pass in
if (actualArgType.isAssignableFrom(expArgType)) {
return am.getAnnotated();
}
}
}
}
return null;
}
{
/* First: return<SCANS> ser)
throws JsonMappingException {
if (prov.isEnabled(SerializationFeature.FAIL_ON_SELF_REFERENCES)
&& !ser.usesObjectId()) {
// 05-Feb-2013, tatu: Usually a problem, but NOT if we are handling
// object id; this may be the case for BeanSerializers at least.
// 13-Feb-2014, tatu: another possible ok case: custom serializer
// (something
// OTHER than {@link BeanSerializerBase}
if (ser instanceof BeanSerializerBase) {
prov.reportMappingProblem("Direct self-reference leading to cycle");
}
}
return false;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder(40);
sb.append("property '").append(getName()).append("' (");
if (_accessorMethod != null) {
sb.append("via method ")
.append(_accessorMethod.getDeclaringClass().getName())
.append("#").append(_accessorMethod.getName());
} else if (_field != null) {
sb.append("field \"").append(_field.getDeclaringClass().getName())
.append("#").append(_field.getName());
} else {
sb.append("virtual");
}
if (_serializer == null) {
sb.append(", no static serializer");
} else {
sb.append(", static serializer of type "
+ _serializer.getClass().getName());
}
sb.append(')');
return sb.toString();
}
}
JacksonDatabind, 65
<FILEB>
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: (%s) %s",
re.getClass().getName(), re.getMessage());
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
if (isFactoryMethod(am) && am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
if (am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
} else {
return null;
}
return new StdKeyDeserializer(kind, raw);
}
@Override
public Object deserializeKey(String key, DeserializationContext ctxt)
throws IOException
{
if (key == null) { // is this even legal call?
return null;
}
try {
Object result = _parse(key, ctxt);
if (result != null) {
return result;
}
} catch (Exception re) {
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: %s", re.getMessage());
<CHANGEE>
}
if (_keyClass.isEnum() && ctxt.getConfig().isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
return null;
}
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation");
}
public Class<?> getKeyClass() { return _keyClass; }
protected Object _parse(String key, DeserializationContext ctxt) throws Exception
{
switch (_kind) {
case TYPE_BOOLEAN:
if ("true".equals(key)) {
<FILEE>
<FILEB>
*/
if (ac.getParameterCount() == 1) {
Class<?> actArg = ac.getRawParameterType(0);
for (Class<?> expArg : argTypes) {
if (expArg == actArg) {
return ac.getAnnotated();
}
}
}
}
return null;
}
@Override
public Method findFactoryMethod(Class<?>... expArgTypes)
{
// So, of all single-arg static methods:
for (AnnotatedMethod am : _classInfo.getStaticMethods()) {
// 24-Oct-2016, tatu: Better ensure it only takes 1 arg, no matter what
<CHANGES>
if (isFactoryMethod(am)) {
<CHANGEE>
// And must take one of expected arg types (or supertype)
Class<?> actualArgType = am.getRawParameterType(0);
for (Class<?> expArgType : expArgTypes) {
// And one that matches what we would pass in
if (actualArgType.isAssignableFrom(expArgType)) {
return am.getAnnotated();
}
}
}
}
return null;
}
{
/* First: return<SCANS> to indicate problem as soon as possible.
*/
if (getClass() != BeanSerializerFactory.class) {
throw new IllegalStateException("Subtype of BeanSerializerFactory ("+getClass().getName()
+") has not properly overridden method 'withAdditionalSerializers': can not instantiate subtype with "
+"additional serializer definitions");
}
return new BeanSerializerFactory(config);
}
@Override
protected Iterable<Serializers> customSerializers() {
return _factoryConfig.serializers();
}
/*
/**********************************************************
/* SerializerFactory impl
/**********************************************************
*/
/**
* Main serializer constructor method. We will have to be careful
* with respect to ordering of various method calls: essentially
* we want to reliably figure out which classes are standard types,
* and which are beans. The problem is that some bean Classes may
* implement standard interfaces (say, {@link java.lang.Iterable}.
*<p>
* Note: sub-classes may choose to complete replace implementation,
* if they want to alter priority of serializer lookups.
*/
@Override
@SuppressWarnings("unchecked")
public JsonSerializer<Object> createSerializer(SerializerProvider prov,
JavaType origType)
throws JsonMappingException
{
// Very first thing, let's check if there is explicit serializer annotation:
final SerializationConfig config = prov.getConfig();
BeanDescription beanDesc = config.introspect(origType);
JsonSerializer<?> ser = findSerializerFromAnnotation(prov, beanDesc.getClassInfo());
if (ser != null) {
return (JsonSerializer<Object>) ser;
}
boolean staticTyping;
// Next: we may have annotations that further indicate actual type to use (a super type)
final AnnotationIntrospector intr = config.getAnnotationIntrospector();
JavaType type;
if (intr == null) {
type = origType;
} else {
try {
type = intr.refineSerializationType(config, beanDesc.getClassInfo(), origType);
} catch (JsonMappingException e) {
return prov.reportBadTypeDefinition(beanDesc, e.getMessage());
}
}
if (type == origType) { // no changes, won't force static typing
staticTyping = false;
} else { // changes; assume static typing; plus, need to re-introspect if class differs
staticTyping = true
JacksonDatabind, 65
<FILEB>
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: (%s) %s",
re.getClass().getName(), re.getMessage());
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
if (isFactoryMethod(am) && am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
if (am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
} else {
return null;
}
return new StdKeyDeserializer(kind, raw);
}
@Override
public Object deserializeKey(String key, DeserializationContext ctxt)
throws IOException
{
if (key == null) { // is this even legal call?
return null;
}
try {
Object result = _parse(key, ctxt);
if (result != null) {
return result;
}
} catch (Exception re) {
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: %s", re.getMessage());
<CHANGEE>
}
if (_keyClass.isEnum() && ctxt.getConfig().isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
return null;
}
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation");
}
public Class<?> getKeyClass() { return _keyClass; }
protected Object _parse(String key, DeserializationContext ctxt) throws Exception
{
switch (_kind) {
case TYPE_BOOLEAN:
if ("true".equals(key)) {
<FILEE>
<FILEB>
*/
if (ac.getParameterCount() == 1) {
Class<?> actArg = ac.getRawParameterType(0);
for (Class<?> expArg : argTypes) {
if (expArg == actArg) {
return ac.getAnnotated();
}
}
}
}
return null;
}
@Override
public Method findFactoryMethod(Class<?>... expArgTypes)
{
// So, of all single-arg static methods:
for (AnnotatedMethod am : _classInfo.getStaticMethods()) {
// 24-Oct-2016, tatu: Better ensure it only takes 1 arg, no matter what
<CHANGES>
if (isFactoryMethod(am)) {
<CHANGEE>
// And must take one of expected arg types (or supertype)
Class<?> actualArgType = am.getRawParameterType(0);
for (Class<?> expArgType : expArgTypes) {
// And one that matches what we would pass in
if (actualArgType.isAssignableFrom(expArgType)) {
return am.getAnnotated();
}
}
}
}
return null;
}
{
/* First: return<SCANS>son 2.7
throw ex;
}
return contextClass.getDeclaredMethods(); // Cross fingers
}
}
/*
/**********************************************************
/* Other methods
/**********************************************************
*/
@Override
public String toString() {
return "[AnnotedClass "+_class.getName()+"]";
}
@Override
public int hashCode() {
return _class.getName().hashCode();
}
@Override
public boolean equals(Object o) {
if (o == this) return true;
if (o == null || o.getClass() != getClass()) return false;
return ((AnnotatedClass) o)._class == _class;
}
}
JacksonDatabind, 65
<FILEB>
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: (%s) %s",
re.getClass().getName(), re.getMessage());
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
if (isFactoryMethod(am) && am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
if (am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
} else {
return null;
}
return new StdKeyDeserializer(kind, raw);
}
@Override
public Object deserializeKey(String key, DeserializationContext ctxt)
throws IOException
{
if (key == null) { // is this even legal call?
return null;
}
try {
Object result = _parse(key, ctxt);
if (result != null) {
return result;
}
} catch (Exception re) {
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: %s", re.getMessage());
<CHANGEE>
}
if (_keyClass.isEnum() && ctxt.getConfig().isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
return null;
}
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation");
}
public Class<?> getKeyClass() { return _keyClass; }
protected Object _parse(String key, DeserializationContext ctxt) throws Exception
{
switch (_kind) {
case TYPE_BOOLEAN:
if ("true".equals(key)) {
<FILEE>
<FILEB>
*/
if (ac.getParameterCount() == 1) {
Class<?> actArg = ac.getRawParameterType(0);
for (Class<?> expArg : argTypes) {
if (expArg == actArg) {
return ac.getAnnotated();
}
}
}
}
return null;
}
@Override
public Method findFactoryMethod(Class<?>... expArgTypes)
{
// So, of all single-arg static methods:
for (AnnotatedMethod am : _classInfo.getStaticMethods()) {
// 24-Oct-2016, tatu: Better ensure it only takes 1 arg, no matter what
<CHANGES>
if (isFactoryMethod(am)) {
<CHANGEE>
// And must take one of expected arg types (or supertype)
Class<?> actualArgType = am.getRawParameterType(0);
for (Class<?> expArgType : expArgTypes) {
// And one that matches what we would pass in
if (actualArgType.isAssignableFrom(expArgType)) {
return am.getAnnotated();
}
}
}
}
return null;
}
{
/* First: return<SCANS>ared type for the property
*/
public abstract VirtualBeanPropertyWriter withConfig(MapperConfig<?> config,
AnnotatedClass declaringClass, BeanPropertyDefinition propDef, JavaType type);
/*
/**********************************************************
/* PropertyWriter serialization method overrides
/**********************************************************
*/
@Override
public void serializeAsField(Object bean, JsonGenerator gen, SerializerProvider prov) throws Exception
{
// NOTE: mostly copied from base class, but off-lined get() access
final Object value = value(bean, gen, prov);
if (value == null) {
if (_nullSerializer != null) {
gen.writeFieldName(_name);
_nullSerializer.serialize(null, gen, prov);
}
return;
}
JsonSerializer<Object> ser = _serializer;
if (ser == null) {
Class<?> cls = value.getClass();
PropertySerializerMap m = _dynamicSerializers;
ser = m.serializerFor(cls);
if (ser == null) {
ser = _findAndAddDynamic(m, cls, prov);
}
}
if (_suppressableValue != null) {
if (MARKER_FOR_EMPTY == _suppressableValue) {
if (ser.isEmpty(prov, value)) {
return;
}
} else if (_suppressableValue.equals(value)) {
return;
}
}
if (value == bean) { // simple check for direct cycles
// three choices: exception; handled by call; or pass-through
if (_handleSelfReference(bean, gen, prov, ser)) {
return;
}
}
gen.writeFieldName(_name);
if (_typeSerializer == null) {
ser.serialize(value, gen, prov);
} else {
ser.serializeWithType(value, gen, prov, _typeSerializer);
}
}
// This one's fine as-is from base class
//public void serializeAsOmittedField(Object bean, JsonGenerator jgen, SerializerProvider prov) throws Exception
@Override
public void serializeAsElement(Object bean, JsonGenerator gen, SerializerProvider prov)
throws Exception
{
// NOTE: mostly copied from base class, but off-lined get() access
final Object value = value(bean, gen, prov);
if (value == null) {
if (_nullSerializer != null) {
JacksonDatabind, 65
<FILEB>
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: (%s) %s",
re.getClass().getName(), re.getMessage());
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
if (isFactoryMethod(am) && am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
if (am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
} else {
return null;
}
return new StdKeyDeserializer(kind, raw);
}
@Override
public Object deserializeKey(String key, DeserializationContext ctxt)
throws IOException
{
if (key == null) { // is this even legal call?
return null;
}
try {
Object result = _parse(key, ctxt);
if (result != null) {
return result;
}
} catch (Exception re) {
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: %s", re.getMessage());
<CHANGEE>
}
if (_keyClass.isEnum() && ctxt.getConfig().isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
return null;
}
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation");
}
public Class<?> getKeyClass() { return _keyClass; }
protected Object _parse(String key, DeserializationContext ctxt) throws Exception
{
switch (_kind) {
case TYPE_BOOLEAN:
if ("true".equals(key)) {
<FILEE>
<FILEB>
*/
if (ac.getParameterCount() == 1) {
Class<?> actArg = ac.getRawParameterType(0);
for (Class<?> expArg : argTypes) {
if (expArg == actArg) {
return ac.getAnnotated();
}
}
}
}
return null;
}
@Override
public Method findFactoryMethod(Class<?>... expArgTypes)
{
// So, of all single-arg static methods:
for (AnnotatedMethod am : _classInfo.getStaticMethods()) {
// 24-Oct-2016, tatu: Better ensure it only takes 1 arg, no matter what
<CHANGES>
if (isFactoryMethod(am)) {
<CHANGEE>
// And must take one of expected arg types (or supertype)
Class<?> actualArgType = am.getRawParameterType(0);
for (Class<?> expArgType : expArgTypes) {
// And one that matches what we would pass in
if (actualArgType.isAssignableFrom(expArgType)) {
return am.getAnnotated();
}
}
}
}
return null;
}
{
/* First: return<SCANS>
_nullSerializer.serialize(null, gen, prov);
} else {
gen.writeNull();
}
return;
}
JsonSerializer<Object> ser = _serializer;
if (ser == null) {
Class<?> cls = value.getClass();
PropertySerializerMap map = _dynamicSerializers;
ser = map.serializerFor(cls);
if (ser == null) {
ser = _findAndAddDynamic(map, cls, prov);
}
}
if (_suppressableValue != null) {
if (MARKER_FOR_EMPTY == _suppressableValue) {
if (ser.isEmpty(prov, value)) {
serializeAsPlaceholder(bean, gen, prov);
return;
}
} else if (_suppressableValue.equals(value)) {
serializeAsPlaceholder(bean, gen, prov);
return;
}
}
if (value == bean) {
if (_handleSelfReference(bean, gen, prov, ser)) {
return;
}
}
if (_typeSerializer == null) {
ser.serialize(value, gen, prov);
} else {
ser.serializeWithType(value, gen, prov, _typeSerializer);
}
}
// This one's fine as-is from base class
//public void serializeAsPlaceholder(Object bean, JsonGenerator jgen, SerializerProvider prov)
}
JacksonDatabind, 65
<FILEB>
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: (%s) %s",
re.getClass().getName(), re.getMessage());
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
if (isFactoryMethod(am) && am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
if (am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
} else {
return null;
}
return new StdKeyDeserializer(kind, raw);
}
@Override
public Object deserializeKey(String key, DeserializationContext ctxt)
throws IOException
{
if (key == null) { // is this even legal call?
return null;
}
try {
Object result = _parse(key, ctxt);
if (result != null) {
return result;
}
} catch (Exception re) {
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: %s", re.getMessage());
<CHANGEE>
}
if (_keyClass.isEnum() && ctxt.getConfig().isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
return null;
}
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation");
}
public Class<?> getKeyClass() { return _keyClass; }
protected Object _parse(String key, DeserializationContext ctxt) throws Exception
{
switch (_kind) {
case TYPE_BOOLEAN:
if ("true".equals(key)) {
<FILEE>
<FILEB>
*/
if (ac.getParameterCount() == 1) {
Class<?> actArg = ac.getRawParameterType(0);
for (Class<?> expArg : argTypes) {
if (expArg == actArg) {
return ac.getAnnotated();
}
}
}
}
return null;
}
@Override
public Method findFactoryMethod(Class<?>... expArgTypes)
{
// So, of all single-arg static methods:
for (AnnotatedMethod am : _classInfo.getStaticMethods()) {
// 24-Oct-2016, tatu: Better ensure it only takes 1 arg, no matter what
<CHANGES>
if (isFactoryMethod(am)) {
<CHANGEE>
// And must take one of expected arg types (or supertype)
Class<?> actualArgType = am.getRawParameterType(0);
for (Class<?> expArgType : expArgTypes) {
// And one that matches what we would pass in
if (actualArgType.isAssignableFrom(expArgType)) {
return am.getAnnotated();
}
}
}
}
return null;
}
{
/* First: return<SCANS>package com.fasterxml.jackson.databind.deser.std;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.deser.SettableBeanProperty;
/**
* Intermediate base deserializer class that adds more shared accessor
* so that other classes can access information about contained (value) types
*/
@SuppressWarnings("serial")
public abstract class ContainerDeserializerBase<T>
extends StdDeserializer<T>
{
protected ContainerDeserializerBase(JavaType selfType) {
super(selfType);
}
/*
/**********************************************************
/* Overrides
/**********************************************************
*/
@Override
public SettableBeanProperty findBackReference(String refName) {
JsonDeserializer<Object> valueDeser = getContentDeserializer();
if (valueDeser == null) {
throw new IllegalArgumentException("Can not handle managed/back reference '"+refName
+"': type: container deserializer of type "+getClass().getName()+" returned null for 'getContentDeserializer()'");
}
return valueDeser.findBackReference(refName);
}
/*
/**********************************************************
/* Extended API
/**********************************************************
*/
/**
* Accessor for declared type of contained value elements; either exact
* type, or one of its supertypes.
*/
public abstract JavaType getContentType();
/**
* Accesor for deserializer use for deserializing content values.
*/
public abstract JsonDeserializer<Object> getContentDeserializer();
/*
/**********************************************************
/* Shared methods for sub-classes
/**********************************************************
*/
/**
* Helper method called by various Map(-like) deserializers.
*/
protected void wrapAndThrow(Throwable t, Object ref, String key) throws IOException
{
// to handle StackOverflow:
while (t instanceof InvocationTargetException && t.getCause() != null) {
t = t.getCause();
}
// Errors and "plain" IOExceptions to be passed as is
if (t instanceof Error) {
throw (Error) t;
}
// ... except for mapping exceptions
if (t instanceof IOException && !(t instanceof JsonMappingException)) {
JacksonDatabind, 65
<FILEB>
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: (%s) %s",
re.getClass().getName(), re.getMessage());
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
if (isFactoryMethod(am) && am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
if (am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
} else {
return null;
}
return new StdKeyDeserializer(kind, raw);
}
@Override
public Object deserializeKey(String key, DeserializationContext ctxt)
throws IOException
{
if (key == null) { // is this even legal call?
return null;
}
try {
Object result = _parse(key, ctxt);
if (result != null) {
return result;
}
} catch (Exception re) {
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: %s", re.getMessage());
<CHANGEE>
}
if (_keyClass.isEnum() && ctxt.getConfig().isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
return null;
}
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation");
}
public Class<?> getKeyClass() { return _keyClass; }
protected Object _parse(String key, DeserializationContext ctxt) throws Exception
{
switch (_kind) {
case TYPE_BOOLEAN:
if ("true".equals(key)) {
<FILEE>
<FILEB>
*/
if (ac.getParameterCount() == 1) {
Class<?> actArg = ac.getRawParameterType(0);
for (Class<?> expArg : argTypes) {
if (expArg == actArg) {
return ac.getAnnotated();
}
}
}
}
return null;
}
@Override
public Method findFactoryMethod(Class<?>... expArgTypes)
{
// So, of all single-arg static methods:
for (AnnotatedMethod am : _classInfo.getStaticMethods()) {
// 24-Oct-2016, tatu: Better ensure it only takes 1 arg, no matter what
<CHANGES>
if (isFactoryMethod(am)) {
<CHANGEE>
// And must take one of expected arg types (or supertype)
Class<?> actualArgType = am.getRawParameterType(0);
for (Class<?> expArgType : expArgTypes) {
// And one that matches what we would pass in
if (actualArgType.isAssignableFrom(expArgType)) {
return am.getAnnotated();
}
}
}
}
return null;
}
{
/* First: return<SCANS>ed description of this instance; needed mostly to
* allow JDK serialization to work in case where {@link #_from} is
* non-serializable (and has to be dropped) but we still want to pass
* actual description along.
*
* @since 2.8
*/
protected String _desc;
/**
* Default constructor for deserialization/sub-classing purposes
*/
protected Reference() { }
public Reference(Object from) { _from = from; }
public Reference(Object from, String fieldName) {
_from = from;
if (fieldName == null) {
throw new NullPointerException("Can not pass null fieldName");
}
_fieldName = fieldName;
}
public Reference(Object from, int index) {
_from = from;
_index = index;
}
// Setters to let Jackson deserialize instances, but not to be called from outside
void setFieldName(String n) { _fieldName = n; }
void setIndex(int ix) { _index = ix; }
void setDescription(String d) { _desc = d; }
/**
* Object through which reference was resolved. Can be either
* actual instance (usually the case for serialization), or
* Class (usually the case for deserialization).
*<p>
* Note that this value must be `transient` to allow serializability (as
* often such Object is NOT serializable; or, in case of `Class`, may
* not available at the point of deserialization). As such will return
* `null` if instance has been passed using JDK serialization.
*/
@JsonIgnore
public Object getFrom() { return _from; }
public String getFieldName() { return _fieldName; }
public int getIndex() { return _index; }
public String getDescription() {
if (_desc == null) {
StringBuilder sb = new StringBuilder();
if (_from == null) { // can this ever occur?
sb.append("UNKNOWN");
} else {
Class<?> cls = (_from instanceof Class<?>) ? (Class<?>)_from : _from.getClass();
// Hmmh. Although Class.getName() is mostly ok, it does look
// butt-ugly for arrays.
// 06-Oct-2016, tatu: as per [databind#14
JacksonDatabind, 65
<FILEB>
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: (%s) %s",
re.getClass().getName(), re.getMessage());
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
if (isFactoryMethod(am) && am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
if (am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
} else {
return null;
}
return new StdKeyDeserializer(kind, raw);
}
@Override
public Object deserializeKey(String key, DeserializationContext ctxt)
throws IOException
{
if (key == null) { // is this even legal call?
return null;
}
try {
Object result = _parse(key, ctxt);
if (result != null) {
return result;
}
} catch (Exception re) {
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: %s", re.getMessage());
<CHANGEE>
}
if (_keyClass.isEnum() && ctxt.getConfig().isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
return null;
}
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation");
}
public Class<?> getKeyClass() { return _keyClass; }
protected Object _parse(String key, DeserializationContext ctxt) throws Exception
{
switch (_kind) {
case TYPE_BOOLEAN:
if ("true".equals(key)) {
<FILEE>
<FILEB>
*/
if (ac.getParameterCount() == 1) {
Class<?> actArg = ac.getRawParameterType(0);
for (Class<?> expArg : argTypes) {
if (expArg == actArg) {
return ac.getAnnotated();
}
}
}
}
return null;
}
@Override
public Method findFactoryMethod(Class<?>... expArgTypes)
{
// So, of all single-arg static methods:
for (AnnotatedMethod am : _classInfo.getStaticMethods()) {
// 24-Oct-2016, tatu: Better ensure it only takes 1 arg, no matter what
<CHANGES>
if (isFactoryMethod(am)) {
<CHANGEE>
// And must take one of expected arg types (or supertype)
Class<?> actualArgType = am.getRawParameterType(0);
for (Class<?> expArgType : expArgTypes) {
// And one that matches what we would pass in
if (actualArgType.isAssignableFrom(expArgType)) {
return am.getAnnotated();
}
}
}
}
return null;
}
{
/* First: return<SCANS>.7
*/
public static JsonMappingException from(JsonGenerator g, String msg, Throwable problem) {
return new JsonMappingException(g, msg, problem);
}
/**
* @since 2.7
*/
public static JsonMappingException from(DeserializationContext ctxt, String msg) {
return new JsonMappingException(ctxt.getParser(), msg);
}
/**
* @since 2.7
*/
public static JsonMappingException from(DeserializationContext ctxt, String msg, Throwable t) {
return new JsonMappingException(ctxt.getParser(), msg, t);
}
/**
* @since 2.7
*/
public static JsonMappingException from(SerializerProvider ctxt, String msg) {
return new JsonMappingException(ctxt.getGenerator(), msg);
}
/**
* @since 2.7
*/
public static JsonMappingException from(SerializerProvider ctxt, String msg, Throwable problem) {
/* 17-Aug-2015, tatu: As per [databind#903] this is bit problematic as
* SerializerProvider instance does not currently hold on to generator...
*/
return new JsonMappingException(ctxt.getGenerator(), msg, problem);
}
/**
* Factory method used when "upgrading" an {@link IOException} into
* {@link JsonMappingException}: usually only needed to comply with
* a signature.
*
* @since 2.1
*/
public static JsonMappingException fromUnexpectedIOE(IOException src) {
return new JsonMappingException(null,
String.format("Unexpected IOException (of type %s): %s",
src.getClass().getName(), src.getMessage()));
}
/**
* Method that can be called to either create a new JsonMappingException
* (if underlying exception is not a JsonMappingException), or augment
* given exception with given path/reference information.
*
* This version of method is called when the reference is through a
* non-indexed object, such as a Map or POJO/bean.
*/
public static JsonMappingException wrapWithPath(Throwable src, Object refFrom,
String refFieldName) {
return wrapWithPath(src, new Reference(refFrom, refFieldName));
}
/**
* Method that can be called to either create a new JsonMapping
JacksonDatabind, 65
<FILEB>
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: (%s) %s",
re.getClass().getName(), re.getMessage());
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
if (isFactoryMethod(am) && am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
if (am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
} else {
return null;
}
return new StdKeyDeserializer(kind, raw);
}
@Override
public Object deserializeKey(String key, DeserializationContext ctxt)
throws IOException
{
if (key == null) { // is this even legal call?
return null;
}
try {
Object result = _parse(key, ctxt);
if (result != null) {
return result;
}
} catch (Exception re) {
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: %s", re.getMessage());
<CHANGEE>
}
if (_keyClass.isEnum() && ctxt.getConfig().isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
return null;
}
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation");
}
public Class<?> getKeyClass() { return _keyClass; }
protected Object _parse(String key, DeserializationContext ctxt) throws Exception
{
switch (_kind) {
case TYPE_BOOLEAN:
if ("true".equals(key)) {
<FILEE>
<FILEB>
*/
if (ac.getParameterCount() == 1) {
Class<?> actArg = ac.getRawParameterType(0);
for (Class<?> expArg : argTypes) {
if (expArg == actArg) {
return ac.getAnnotated();
}
}
}
}
return null;
}
@Override
public Method findFactoryMethod(Class<?>... expArgTypes)
{
// So, of all single-arg static methods:
for (AnnotatedMethod am : _classInfo.getStaticMethods()) {
// 24-Oct-2016, tatu: Better ensure it only takes 1 arg, no matter what
<CHANGES>
if (isFactoryMethod(am)) {
<CHANGEE>
// And must take one of expected arg types (or supertype)
Class<?> actualArgType = am.getRawParameterType(0);
for (Class<?> expArgType : expArgTypes) {
// And one that matches what we would pass in
if (actualArgType.isAssignableFrom(expArgType)) {
return am.getAnnotated();
}
}
}
}
return null;
}
{
/* First: return<SCANS>Exception
* (if underlying exception is not a JsonMappingException), or augment
* given exception with given path/reference information.
*
* This version of method is called when the reference is through an
* index, which happens with arrays and Collections.
*/
public static JsonMappingException wrapWithPath(Throwable src, Object refFrom, int index) {
return wrapWithPath(src, new Reference(refFrom, index));
}
/**
* Method that can be called to either create a new JsonMappingException
* (if underlying exception is not a JsonMappingException), or augment
* given exception with given path/reference information.
*/
@SuppressWarnings("resource")
public static JsonMappingException wrapWithPath(Throwable src, Reference ref)
{
JsonMappingException jme;
if (src instanceof JsonMappingException) {
jme = (JsonMappingException) src;
} else {
String msg = src.getMessage();
// Let's use a more meaningful placeholder if all we have is null
if (msg == null || msg.length() == 0) {
msg = "(was "+src.getClass().getName()+")";
}
// 17-Aug-2015, tatu: Let's also pass the processor (parser/generator) along
Closeable proc = null;
if (src instanceof JsonProcessingException) {
Object proc0 = ((JsonProcessingException) src).getProcessor();
if (proc0 instanceof Closeable) {
proc = (Closeable) proc0;
}
}
jme = new JsonMappingException(proc, msg, src);
}
jme.prependPath(ref);
return jme;
}
/*
/**********************************************************
/* Accessors/mutators
/**********************************************************
*/
/**
* Method for accessing full structural path within type hierarchy
* down to problematic property.
*/
public List<Reference> getPath()
{
if (_path == null) {
return Collections.emptyList();
}
return Collections.unmodifiableList(_path);
}
/**
* Method for accessing description of path that lead to the
* problem that triggered this exception
*/
public String getPathReference()
{
return getPathReference(new StringBuilder()).toString();
}
public StringBuilder getPathReference(StringBuilder sb)
{
_appendPathDesc(sb);
return
JacksonDatabind, 65
<FILEB>
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: (%s) %s",
re.getClass().getName(), re.getMessage());
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
if (isFactoryMethod(am) && am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
if (am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
} else {
return null;
}
return new StdKeyDeserializer(kind, raw);
}
@Override
public Object deserializeKey(String key, DeserializationContext ctxt)
throws IOException
{
if (key == null) { // is this even legal call?
return null;
}
try {
Object result = _parse(key, ctxt);
if (result != null) {
return result;
}
} catch (Exception re) {
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: %s", re.getMessage());
<CHANGEE>
}
if (_keyClass.isEnum() && ctxt.getConfig().isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
return null;
}
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation");
}
public Class<?> getKeyClass() { return _keyClass; }
protected Object _parse(String key, DeserializationContext ctxt) throws Exception
{
switch (_kind) {
case TYPE_BOOLEAN:
if ("true".equals(key)) {
<FILEE>
<FILEB>
*/
if (ac.getParameterCount() == 1) {
Class<?> actArg = ac.getRawParameterType(0);
for (Class<?> expArg : argTypes) {
if (expArg == actArg) {
return ac.getAnnotated();
}
}
}
}
return null;
}
@Override
public Method findFactoryMethod(Class<?>... expArgTypes)
{
// So, of all single-arg static methods:
for (AnnotatedMethod am : _classInfo.getStaticMethods()) {
// 24-Oct-2016, tatu: Better ensure it only takes 1 arg, no matter what
<CHANGES>
if (isFactoryMethod(am)) {
<CHANGEE>
// And must take one of expected arg types (or supertype)
Class<?> actualArgType = am.getRawParameterType(0);
for (Class<?> expArgType : expArgTypes) {
// And one that matches what we would pass in
if (actualArgType.isAssignableFrom(expArgType)) {
return am.getAnnotated();
}
}
}
}
return null;
}
{
/* First: return<SCANS> public String toString()
{
return getClass().getName()+": "+getMessage();
}
/*
/**********************************************************
/* Internal methods
/**********************************************************
*/
protected void _appendPathDesc(StringBuilder sb)
{
if (_path == null) {
return;
}
Iterator<Reference> it = _path.iterator();
while (it.hasNext()) {
sb.append(it.next().toString());
if (it.hasNext()) {
sb.append("->");
}
}
}
}
JacksonDatabind, 65
<FILEB>
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: (%s) %s",
re.getClass().getName(), re.getMessage());
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
if (isFactoryMethod(am) && am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
if (am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
} else {
return null;
}
return new StdKeyDeserializer(kind, raw);
}
@Override
public Object deserializeKey(String key, DeserializationContext ctxt)
throws IOException
{
if (key == null) { // is this even legal call?
return null;
}
try {
Object result = _parse(key, ctxt);
if (result != null) {
return result;
}
} catch (Exception re) {
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: %s", re.getMessage());
<CHANGEE>
}
if (_keyClass.isEnum() && ctxt.getConfig().isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
return null;
}
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation");
}
public Class<?> getKeyClass() { return _keyClass; }
protected Object _parse(String key, DeserializationContext ctxt) throws Exception
{
switch (_kind) {
case TYPE_BOOLEAN:
if ("true".equals(key)) {
<FILEE>
<FILEB>
*/
if (ac.getParameterCount() == 1) {
Class<?> actArg = ac.getRawParameterType(0);
for (Class<?> expArg : argTypes) {
if (expArg == actArg) {
return ac.getAnnotated();
}
}
}
}
return null;
}
@Override
public Method findFactoryMethod(Class<?>... expArgTypes)
{
// So, of all single-arg static methods:
for (AnnotatedMethod am : _classInfo.getStaticMethods()) {
// 24-Oct-2016, tatu: Better ensure it only takes 1 arg, no matter what
<CHANGES>
if (isFactoryMethod(am)) {
<CHANGEE>
// And must take one of expected arg types (or supertype)
Class<?> actualArgType = am.getRawParameterType(0);
for (Class<?> expArgType : expArgTypes) {
// And one that matches what we would pass in
if (actualArgType.isAssignableFrom(expArgType)) {
return am.getAnnotated();
}
}
}
}
return null;
}
{
/* First: return<SCANS> null) {
serializeUsing(value, gen, provider, _valueSerializer);
} else {
serializeDynamic(value, gen, provider);
}
typeSer.writeTypeSuffixForObject(value, gen);
}
protected void serializeDynamic(Map.Entry<?, ?> value, JsonGenerator jgen, SerializerProvider provider)
throws IOException
{
final JsonSerializer<Object> keySerializer = _keySerializer;
final boolean skipNulls = !provider.isEnabled(SerializationFeature.WRITE_NULL_MAP_VALUES);
final TypeSerializer vts = _valueTypeSerializer;
PropertySerializerMap serializers = _dynamicValueSerializers;
Object valueElem = value.getValue();
Object keyElem = value.getKey();
if (keyElem == null) {
provider.findNullKeySerializer(_keyType, _property).serialize(null, jgen, provider);
} else {
// [JACKSON-314] skip entries with null values?
if (skipNulls && valueElem == null) return;
keySerializer.serialize(keyElem, jgen, provider);
}
// And then value
if (valueElem == null) {
provider.defaultSerializeNull(jgen);
} else {
Class<?> cc = valueElem.getClass();
JsonSerializer<Object> ser = serializers.serializerFor(cc);
if (ser == null) {
if (_valueType.hasGenericTypes()) {
ser = _findAndAddDynamic(serializers,
provider.constructSpecializedType(_valueType, cc), provider);
} else {
ser = _findAndAddDynamic(serializers, cc, provider);
}
serializers = _dynamicValueSerializers;
}
try {
if (vts == null) {
ser.serialize(valueElem, jgen, provider);
} else {
ser.serializeWithType(valueElem, jgen, provider, vts);
}
} catch (Exception e) {
// [JACKSON-55] Need to add reference information
String keyDesc = ""+keyElem;
wrapAndThrow(provider, e, value, keyDesc);
}
}
}
/**
* Method called to serialize fields, when the value type is statically known,
* so that value serializer is passed and does not need to be fetched from
* provider.
*/
protected void serialize
JacksonDatabind, 65
<FILEB>
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: (%s) %s",
re.getClass().getName(), re.getMessage());
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
if (isFactoryMethod(am) && am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
if (am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
} else {
return null;
}
return new StdKeyDeserializer(kind, raw);
}
@Override
public Object deserializeKey(String key, DeserializationContext ctxt)
throws IOException
{
if (key == null) { // is this even legal call?
return null;
}
try {
Object result = _parse(key, ctxt);
if (result != null) {
return result;
}
} catch (Exception re) {
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: %s", re.getMessage());
<CHANGEE>
}
if (_keyClass.isEnum() && ctxt.getConfig().isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
return null;
}
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation");
}
public Class<?> getKeyClass() { return _keyClass; }
protected Object _parse(String key, DeserializationContext ctxt) throws Exception
{
switch (_kind) {
case TYPE_BOOLEAN:
if ("true".equals(key)) {
<FILEE>
<FILEB>
*/
if (ac.getParameterCount() == 1) {
Class<?> actArg = ac.getRawParameterType(0);
for (Class<?> expArg : argTypes) {
if (expArg == actArg) {
return ac.getAnnotated();
}
}
}
}
return null;
}
@Override
public Method findFactoryMethod(Class<?>... expArgTypes)
{
// So, of all single-arg static methods:
for (AnnotatedMethod am : _classInfo.getStaticMethods()) {
// 24-Oct-2016, tatu: Better ensure it only takes 1 arg, no matter what
<CHANGES>
if (isFactoryMethod(am)) {
<CHANGEE>
// And must take one of expected arg types (or supertype)
Class<?> actualArgType = am.getRawParameterType(0);
for (Class<?> expArgType : expArgTypes) {
// And one that matches what we would pass in
if (actualArgType.isAssignableFrom(expArgType)) {
return am.getAnnotated();
}
}
}
}
return null;
}
{
/* First: return<SCANS> /**********************************************************
*/
/**
* Method that can be called to ask implementation to serialize
* values of type this serializer handles.
*
* @param value Value to serialize; can <b>not</b> be null.
* @param gen Generator used to output resulting Json content
* @param serializers Provider that can be used to get serializers for
* serializing Objects value contains, if any.
*/
public abstract void serialize(T value, JsonGenerator gen, SerializerProvider serializers)
throws IOException, JsonProcessingException;
/**
* Method that can be called to ask implementation to serialize
* values of type this serializer handles, using specified type serializer
* for embedding necessary type information.
*<p>
* Default implementation will throw {@link UnsupportedOperationException}
* to indicate that proper type handling needs to be implemented.
*<p>
* For simple datatypes written as a single scalar value (JSON String, Number, Boolean),
* implementation would look like:
*<pre>
* // note: method to call depends on whether this type is serialized as JSON scalar, object or Array!
* typeSer.writeTypePrefixForScalar(value, gen);
* serialize(value, gen, provider);
* typeSer.writeTypeSuffixForScalar(value, gen);
*</pre>
* and implementations for type serialized as JSON Arrays or Objects would differ slightly,
* as <code>START-ARRAY</code>/<code>END-ARRAY</code> and
* <code>START-OBJECT</code>/<code>END-OBJECT</code> pairs
* need to be properly handled with respect to serializing of contents.
*
* @param value Value to serialize; can <b>not</b> be null.
* @param gen Generator used to output resulting Json content
* @param serializers Provider that can be used to get serializers for
* serializing Objects value contains, if any.
* @param typeSer Type serializer to use for including type information
*/
public void serializeWithType(T value, JsonGenerator gen, SerializerProvider serializers,
TypeSerializer typeSer)
throws IOException
{
Class<?> clz = handledType();
if (clz == null) {
clz = value.getClass();
}
serializers.reportMappingProblem("Type id handling not implemented for type %s (by
JacksonDatabind, 65
<FILEB>
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: (%s) %s",
re.getClass().getName(), re.getMessage());
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
if (isFactoryMethod(am) && am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
if (am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
} else {
return null;
}
return new StdKeyDeserializer(kind, raw);
}
@Override
public Object deserializeKey(String key, DeserializationContext ctxt)
throws IOException
{
if (key == null) { // is this even legal call?
return null;
}
try {
Object result = _parse(key, ctxt);
if (result != null) {
return result;
}
} catch (Exception re) {
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: %s", re.getMessage());
<CHANGEE>
}
if (_keyClass.isEnum() && ctxt.getConfig().isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
return null;
}
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation");
}
public Class<?> getKeyClass() { return _keyClass; }
protected Object _parse(String key, DeserializationContext ctxt) throws Exception
{
switch (_kind) {
case TYPE_BOOLEAN:
if ("true".equals(key)) {
<FILEE>
<FILEB>
*/
if (ac.getParameterCount() == 1) {
Class<?> actArg = ac.getRawParameterType(0);
for (Class<?> expArg : argTypes) {
if (expArg == actArg) {
return ac.getAnnotated();
}
}
}
}
return null;
}
@Override
public Method findFactoryMethod(Class<?>... expArgTypes)
{
// So, of all single-arg static methods:
for (AnnotatedMethod am : _classInfo.getStaticMethods()) {
// 24-Oct-2016, tatu: Better ensure it only takes 1 arg, no matter what
<CHANGES>
if (isFactoryMethod(am)) {
<CHANGEE>
// And must take one of expected arg types (or supertype)
Class<?> actualArgType = am.getRawParameterType(0);
for (Class<?> expArgType : expArgTypes) {
// And one that matches what we would pass in
if (actualArgType.isAssignableFrom(expArgType)) {
return am.getAnnotated();
}
}
}
}
return null;
}
{
/* First: return<SCANS> serializer of type %s)",
clz.getName(), getClass().getName());
}
/*
/**********************************************************
/* Other accessors
/**********************************************************
*/
/**
* Method for accessing type of Objects this serializer can handle.
* Note that this information is not guaranteed to be exact -- it
* may be a more generic (super-type) -- but it should not be
* incorrect (return a non-related type).
*<p>
* Default implementation will return null, which essentially means
* same as returning <code>Object.class</code> would; that is, that
* nothing is known about handled type.
*<p>
*/
public Class<T> handledType() { return null; }
/**
* Method called to check whether given serializable value is
* considered "empty" value (for purposes of suppressing serialization
* of empty values).
*<p>
* Default implementation will consider only null values to be empty.
*
* @deprecated Since 2.5 Use {@link #isEmpty(SerializerProvider, Object)} instead;
* will be removed from 2.9
*/
@Deprecated
public boolean isEmpty(T value) {
return isEmpty(null, value);
}
/**
* Method called to check whether given serializable value is
* considered "empty" value (for purposes of suppressing serialization
* of empty values).
*<p>
* Default implementation will consider only null values to be empty.
*<p>
* NOTE: replaces {@link #isEmpty(Object)}, which was deprecated in 2.5
*
* @since 2.5
*/
public boolean isEmpty(SerializerProvider provider, T value) {
return (value == null);
}
/**
* Method that can be called to see whether this serializer instance
* will use Object Id to handle cyclic references.
*/
public boolean usesObjectId() {
return false;
}
/**
* Accessor for checking whether this serializer is an
* "unwrapping" serializer; this is necessary to know since
* it may also require caller to suppress writing of the
* leading property name.
*/
public boolean isUnwrappingSerializer() {
return false;
}
/**
* Accessor that can be used to determine if this serializer uses
* another serializer for actual serialization, by
JacksonDatabind, 65
<FILEB>
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: (%s) %s",
re.getClass().getName(), re.getMessage());
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
if (isFactoryMethod(am) && am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
if (am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
} else {
return null;
}
return new StdKeyDeserializer(kind, raw);
}
@Override
public Object deserializeKey(String key, DeserializationContext ctxt)
throws IOException
{
if (key == null) { // is this even legal call?
return null;
}
try {
Object result = _parse(key, ctxt);
if (result != null) {
return result;
}
} catch (Exception re) {
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: %s", re.getMessage());
<CHANGEE>
}
if (_keyClass.isEnum() && ctxt.getConfig().isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
return null;
}
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation");
}
public Class<?> getKeyClass() { return _keyClass; }
protected Object _parse(String key, DeserializationContext ctxt) throws Exception
{
switch (_kind) {
case TYPE_BOOLEAN:
if ("true".equals(key)) {
<FILEE>
<FILEB>
*/
if (ac.getParameterCount() == 1) {
Class<?> actArg = ac.getRawParameterType(0);
for (Class<?> expArg : argTypes) {
if (expArg == actArg) {
return ac.getAnnotated();
}
}
}
}
return null;
}
@Override
public Method findFactoryMethod(Class<?>... expArgTypes)
{
// So, of all single-arg static methods:
for (AnnotatedMethod am : _classInfo.getStaticMethods()) {
// 24-Oct-2016, tatu: Better ensure it only takes 1 arg, no matter what
<CHANGES>
if (isFactoryMethod(am)) {
<CHANGEE>
// And must take one of expected arg types (or supertype)
Class<?> actualArgType = am.getRawParameterType(0);
for (Class<?> expArgType : expArgTypes) {
// And one that matches what we would pass in
if (actualArgType.isAssignableFrom(expArgType)) {
return am.getAnnotated();
}
}
}
}
return null;
}
{
/* First: return<SCANS> 1) {
if (((_unwrapSingle == null) &&
provider.isEnabled(SerializationFeature.WRITE_SINGLE_ELEM_ARRAYS_UNWRAPPED))
|| (_unwrapSingle == Boolean.TRUE)) {
serializeContents(value, gen, provider);
return;
}
}
gen.writeStartArray(len);
serializeContents(value, gen, provider);
gen.writeEndArray();
}
@Override
public void serializeContents(List<?> value, JsonGenerator jgen, SerializerProvider provider)
throws IOException
{
if (_elementSerializer != null) {
serializeContentsUsing(value, jgen, provider, _elementSerializer);
return;
}
if (_valueTypeSerializer != null) {
serializeTypedContents(value, jgen, provider);
return;
}
final int len = value.size();
if (len == 0) {
return;
}
int i = 0;
try {
PropertySerializerMap serializers = _dynamicSerializers;
for (; i < len; ++i) {
Object elem = value.get(i);
if (elem == null) {
provider.defaultSerializeNull(jgen);
} else {
Class<?> cc = elem.getClass();
JsonSerializer<Object> serializer = serializers.serializerFor(cc);
if (serializer == null) {
// To fix [JACKSON-508]
if (_elementType.hasGenericTypes()) {
serializer = _findAndAddDynamic(serializers,
provider.constructSpecializedType(_elementType, cc), provider);
} else {
serializer = _findAndAddDynamic(serializers, cc, provider);
}
serializers = _dynamicSerializers;
}
serializer.serialize(elem, jgen, provider);
}
}
} catch (Exception e) {
wrapAndThrow(provider, e, value, i);
}
}
public void serializeContentsUsing(List<?> value, JsonGenerator jgen, SerializerProvider provider,
JsonSerializer<Object> ser)
throws IOException
{
final int len = value.size();
if (len == 0) {
return;
}
final TypeSerializer typeSer = _valueTypeSerializer;
for (int i = 0; i < len; ++i) {
Object elem = value.get(i);
try {
JacksonDatabind, 65
<FILEB>
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: (%s) %s",
re.getClass().getName(), re.getMessage());
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
if (isFactoryMethod(am) && am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
if (am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
} else {
return null;
}
return new StdKeyDeserializer(kind, raw);
}
@Override
public Object deserializeKey(String key, DeserializationContext ctxt)
throws IOException
{
if (key == null) { // is this even legal call?
return null;
}
try {
Object result = _parse(key, ctxt);
if (result != null) {
return result;
}
} catch (Exception re) {
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: %s", re.getMessage());
<CHANGEE>
}
if (_keyClass.isEnum() && ctxt.getConfig().isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
return null;
}
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation");
}
public Class<?> getKeyClass() { return _keyClass; }
protected Object _parse(String key, DeserializationContext ctxt) throws Exception
{
switch (_kind) {
case TYPE_BOOLEAN:
if ("true".equals(key)) {
<FILEE>
<FILEB>
*/
if (ac.getParameterCount() == 1) {
Class<?> actArg = ac.getRawParameterType(0);
for (Class<?> expArg : argTypes) {
if (expArg == actArg) {
return ac.getAnnotated();
}
}
}
}
return null;
}
@Override
public Method findFactoryMethod(Class<?>... expArgTypes)
{
// So, of all single-arg static methods:
for (AnnotatedMethod am : _classInfo.getStaticMethods()) {
// 24-Oct-2016, tatu: Better ensure it only takes 1 arg, no matter what
<CHANGES>
if (isFactoryMethod(am)) {
<CHANGEE>
// And must take one of expected arg types (or supertype)
Class<?> actualArgType = am.getRawParameterType(0);
for (Class<?> expArgType : expArgTypes) {
// And one that matches what we would pass in
if (actualArgType.isAssignableFrom(expArgType)) {
return am.getAnnotated();
}
}
}
}
return null;
}
{
/* First: return<SCANS> if (elem == null) {
provider.defaultSerializeNull(jgen);
} else if (typeSer == null) {
ser.serialize(elem, jgen, provider);
} else {
ser.serializeWithType(elem, jgen, provider, typeSer);
}
} catch (Exception e) {
// [JACKSON-55] Need to add reference information
wrapAndThrow(provider, e, value, i);
}
}
}
public void serializeTypedContents(List<?> value, JsonGenerator jgen, SerializerProvider provider)
throws IOException
{
final int len = value.size();
if (len == 0) {
return;
}
int i = 0;
try {
final TypeSerializer typeSer = _valueTypeSerializer;
PropertySerializerMap serializers = _dynamicSerializers;
for (; i < len; ++i) {
Object elem = value.get(i);
if (elem == null) {
provider.defaultSerializeNull(jgen);
} else {
Class<?> cc = elem.getClass();
JsonSerializer<Object> serializer = serializers.serializerFor(cc);
if (serializer == null) {
// To fix [JACKSON-508]
if (_elementType.hasGenericTypes()) {
serializer = _findAndAddDynamic(serializers,
provider.constructSpecializedType(_elementType, cc), provider);
} else {
serializer = _findAndAddDynamic(serializers, cc, provider);
}
serializers = _dynamicSerializers;
}
serializer.serializeWithType(elem, jgen, provider, typeSer);
}
}
} catch (Exception e) {
// [JACKSON-55] Need to add reference information
wrapAndThrow(provider, e, value, i);
}
}
}
JacksonDatabind, 65
<FILEB>
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: (%s) %s",
re.getClass().getName(), re.getMessage());
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
if (isFactoryMethod(am) && am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
if (am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
} else {
return null;
}
return new StdKeyDeserializer(kind, raw);
}
@Override
public Object deserializeKey(String key, DeserializationContext ctxt)
throws IOException
{
if (key == null) { // is this even legal call?
return null;
}
try {
Object result = _parse(key, ctxt);
if (result != null) {
return result;
}
} catch (Exception re) {
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: %s", re.getMessage());
<CHANGEE>
}
if (_keyClass.isEnum() && ctxt.getConfig().isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
return null;
}
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation");
}
public Class<?> getKeyClass() { return _keyClass; }
protected Object _parse(String key, DeserializationContext ctxt) throws Exception
{
switch (_kind) {
case TYPE_BOOLEAN:
if ("true".equals(key)) {
<FILEE>
<FILEB>
*/
if (ac.getParameterCount() == 1) {
Class<?> actArg = ac.getRawParameterType(0);
for (Class<?> expArg : argTypes) {
if (expArg == actArg) {
return ac.getAnnotated();
}
}
}
}
return null;
}
@Override
public Method findFactoryMethod(Class<?>... expArgTypes)
{
// So, of all single-arg static methods:
for (AnnotatedMethod am : _classInfo.getStaticMethods()) {
// 24-Oct-2016, tatu: Better ensure it only takes 1 arg, no matter what
<CHANGES>
if (isFactoryMethod(am)) {
<CHANGEE>
// And must take one of expected arg types (or supertype)
Class<?> actualArgType = am.getRawParameterType(0);
for (Class<?> expArgType : expArgTypes) {
// And one that matches what we would pass in
if (actualArgType.isAssignableFrom(expArgType)) {
return am.getAnnotated();
}
}
}
}
return null;
}
{
/* First: return<SCANS> getGenericType() {
return _owner.getGenericParameterType(_index);
}
/*
/**********************************************************
/* AnnotatedMember extras
/**********************************************************
*/
@Override
public Class<?> getDeclaringClass() {
return _owner.getDeclaringClass();
}
@Override
public Member getMember() {
/* This is bit tricky: since there is no JDK equivalent; can either
* return null or owner... let's do latter, for now.
*/
return _owner.getMember();
}
@Override
public void setValue(Object pojo, Object value) throws UnsupportedOperationException
{
throw new UnsupportedOperationException("Cannot call setValue() on constructor parameter of "
+getDeclaringClass().getName());
}
@Override
public Object getValue(Object pojo) throws UnsupportedOperationException
{
throw new UnsupportedOperationException("Cannot call getValue() on constructor parameter of "
+getDeclaringClass().getName());
}
/*
/**********************************************************
/* Extended API
/**********************************************************
*/
public Type getParameterType() { return _type; }
/**
* Accessor for 'owner' of this parameter; method or constructor that
* has this parameter as member of its argument list.
*
* @return Owner (member or creator) object of this parameter
*/
public AnnotatedWithParams getOwner() { return _owner; }
/**
* Accessor for index of this parameter within argument list
*
* @return Index of this parameter within argument list
*/
public int getIndex() { return _index; }
/*
/********************************************************
/* Other
/********************************************************
*/
@Override
public int hashCode() {
return _owner.hashCode() + _index;
}
@Override
public boolean equals(Object o) {
if (o == this) return true;
if (o == null || o.getClass() != getClass()) return false;
AnnotatedParameter other = (AnnotatedParameter) o;
return other._owner.equals(_owner) && (other._index == _index);
}
@Override
public String toString() {
return "[parameter #"+getIndex()+", annotations: "+_annotations+"]";
}
}
JacksonDatabind, 65
<FILEB>
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: (%s) %s",
re.getClass().getName(), re.getMessage());
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
if (isFactoryMethod(am) && am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
if (am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
} else {
return null;
}
return new StdKeyDeserializer(kind, raw);
}
@Override
public Object deserializeKey(String key, DeserializationContext ctxt)
throws IOException
{
if (key == null) { // is this even legal call?
return null;
}
try {
Object result = _parse(key, ctxt);
if (result != null) {
return result;
}
} catch (Exception re) {
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: %s", re.getMessage());
<CHANGEE>
}
if (_keyClass.isEnum() && ctxt.getConfig().isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
return null;
}
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation");
}
public Class<?> getKeyClass() { return _keyClass; }
protected Object _parse(String key, DeserializationContext ctxt) throws Exception
{
switch (_kind) {
case TYPE_BOOLEAN:
if ("true".equals(key)) {
<FILEE>
<FILEB>
*/
if (ac.getParameterCount() == 1) {
Class<?> actArg = ac.getRawParameterType(0);
for (Class<?> expArg : argTypes) {
if (expArg == actArg) {
return ac.getAnnotated();
}
}
}
}
return null;
}
@Override
public Method findFactoryMethod(Class<?>... expArgTypes)
{
// So, of all single-arg static methods:
for (AnnotatedMethod am : _classInfo.getStaticMethods()) {
// 24-Oct-2016, tatu: Better ensure it only takes 1 arg, no matter what
<CHANGES>
if (isFactoryMethod(am)) {
<CHANGEE>
// And must take one of expected arg types (or supertype)
Class<?> actualArgType = am.getRawParameterType(0);
for (Class<?> expArgType : expArgTypes) {
// And one that matches what we would pass in
if (actualArgType.isAssignableFrom(expArgType)) {
return am.getAnnotated();
}
}
}
}
return null;
}
{
/* First: return<SCANS> new CollectionDeserializer(_collectionType,
(JsonDeserializer<Object>) vd, vtd,
_valueInstantiator, (JsonDeserializer<Object>) dd, unwrapSingle);
}
/**
* @deprecated Since 2.7 as it does not pass `unwrapSingle`
*/
@Deprecated // since 2.7 -- will not retain "unwrapSingle" setting
protected CollectionDeserializer withResolved(JsonDeserializer<?> dd,
JsonDeserializer<?> vd, TypeDeserializer vtd)
{
return withResolved(dd, vd, vtd, _unwrapSingle);
}
// Important: do NOT cache if polymorphic values
@Override // since 2.5
public boolean isCachable() {
// 26-Mar-2015, tatu: As per [databind#735], need to be careful
return (_valueDeserializer == null)
&& (_valueTypeDeserializer == null)
&& (_delegateDeserializer == null)
;
}
/*
/**********************************************************
/* Validation, post-processing (ResolvableDeserializer)
/**********************************************************
*/
/**
* Method called to finalize setup of this deserializer,
* when it is known for which property deserializer is needed
* for.
*/
@Override
public CollectionDeserializer createContextual(DeserializationContext ctxt,
BeanProperty property) throws JsonMappingException
{
// May need to resolve types for delegate-based creators:
JsonDeserializer<Object> delegateDeser = null;
if (_valueInstantiator != null) {
if (_valueInstantiator.canCreateUsingDelegate()) {
JavaType delegateType = _valueInstantiator.getDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid delegate-creator definition for "+_collectionType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingDelegate()', but null for 'getDelegateType()'");
}
delegateDeser = findDeserializer(ctxt, delegateType, property);
} else if (_valueInstantiator.canCreateUsingArrayDelegate()) {
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_collectionType
+": value instantiator ("+_
JacksonDatabind, 65
<FILEB>
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: (%s) %s",
re.getClass().getName(), re.getMessage());
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
if (isFactoryMethod(am) && am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
if (am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
} else {
return null;
}
return new StdKeyDeserializer(kind, raw);
}
@Override
public Object deserializeKey(String key, DeserializationContext ctxt)
throws IOException
{
if (key == null) { // is this even legal call?
return null;
}
try {
Object result = _parse(key, ctxt);
if (result != null) {
return result;
}
} catch (Exception re) {
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: %s", re.getMessage());
<CHANGEE>
}
if (_keyClass.isEnum() && ctxt.getConfig().isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
return null;
}
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation");
}
public Class<?> getKeyClass() { return _keyClass; }
protected Object _parse(String key, DeserializationContext ctxt) throws Exception
{
switch (_kind) {
case TYPE_BOOLEAN:
if ("true".equals(key)) {
<FILEE>
<FILEB>
*/
if (ac.getParameterCount() == 1) {
Class<?> actArg = ac.getRawParameterType(0);
for (Class<?> expArg : argTypes) {
if (expArg == actArg) {
return ac.getAnnotated();
}
}
}
}
return null;
}
@Override
public Method findFactoryMethod(Class<?>... expArgTypes)
{
// So, of all single-arg static methods:
for (AnnotatedMethod am : _classInfo.getStaticMethods()) {
// 24-Oct-2016, tatu: Better ensure it only takes 1 arg, no matter what
<CHANGES>
if (isFactoryMethod(am)) {
<CHANGEE>
// And must take one of expected arg types (or supertype)
Class<?> actualArgType = am.getRawParameterType(0);
for (Class<?> expArgType : expArgTypes) {
// And one that matches what we would pass in
if (actualArgType.isAssignableFrom(expArgType)) {
return am.getAnnotated();
}
}
}
}
return null;
}
{
/* First: return<SCANS>valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
}
delegateDeser = findDeserializer(ctxt, delegateType, property);
}
}
// [databind#1043]: allow per-property allow-wrapping of single overrides:
// 11-Dec-2015, tatu: Should we pass basic `Collection.class`, or more refined? Mostly
// comes down to "List vs Collection" I suppose... for now, pass Collection
Boolean unwrapSingle = findFormatFeature(ctxt, property, Collection.class,
JsonFormat.Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY);
// also, often value deserializer is resolved here:
JsonDeserializer<?> valueDeser = _valueDeserializer;
// May have a content converter
valueDeser = findConvertingContentDeserializer(ctxt, property, valueDeser);
final JavaType vt = _collectionType.getContentType();
if (valueDeser == null) {
valueDeser = ctxt.findContextualValueDeserializer(vt, property);
} else { // if directly assigned, probably not yet contextual, so:
valueDeser = ctxt.handleSecondaryContextualization(valueDeser, property, vt);
}
// and finally, type deserializer needs context as well
TypeDeserializer valueTypeDeser = _valueTypeDeserializer;
if (valueTypeDeser != null) {
valueTypeDeser = valueTypeDeser.forProperty(property);
}
return withResolved(delegateDeser, valueDeser, valueTypeDeser, unwrapSingle);
}
/*
/**********************************************************
/* ContainerDeserializerBase API
/**********************************************************
*/
@Override
public JavaType getContentType() {
return _collectionType.getContentType();
}
@Override
public JsonDeserializer<Object> getContentDeserializer() {
return _valueDeserializer;
}
/*
/**********************************************************
/* JsonDeserializer API
/**********************************************************
*/
@SuppressWarnings("unchecked")
@Override
public Collection<Object> deserialize(JsonParser p, DeserializationContext ctxt)
throws IOException
{
if (_delegateDeserializer != null) {
return (Collection<Object>) _valueInstantiator.createUsingDelegate(ctxt,
_delegateDeserializer.deserialize(p, ctxt
JacksonDatabind, 65
<FILEB>
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: (%s) %s",
re.getClass().getName(), re.getMessage());
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
if (isFactoryMethod(am) && am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
if (am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
} else {
return null;
}
return new StdKeyDeserializer(kind, raw);
}
@Override
public Object deserializeKey(String key, DeserializationContext ctxt)
throws IOException
{
if (key == null) { // is this even legal call?
return null;
}
try {
Object result = _parse(key, ctxt);
if (result != null) {
return result;
}
} catch (Exception re) {
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: %s", re.getMessage());
<CHANGEE>
}
if (_keyClass.isEnum() && ctxt.getConfig().isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
return null;
}
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation");
}
public Class<?> getKeyClass() { return _keyClass; }
protected Object _parse(String key, DeserializationContext ctxt) throws Exception
{
switch (_kind) {
case TYPE_BOOLEAN:
if ("true".equals(key)) {
<FILEE>
<FILEB>
*/
if (ac.getParameterCount() == 1) {
Class<?> actArg = ac.getRawParameterType(0);
for (Class<?> expArg : argTypes) {
if (expArg == actArg) {
return ac.getAnnotated();
}
}
}
}
return null;
}
@Override
public Method findFactoryMethod(Class<?>... expArgTypes)
{
// So, of all single-arg static methods:
for (AnnotatedMethod am : _classInfo.getStaticMethods()) {
// 24-Oct-2016, tatu: Better ensure it only takes 1 arg, no matter what
<CHANGES>
if (isFactoryMethod(am)) {
<CHANGEE>
// And must take one of expected arg types (or supertype)
Class<?> actualArgType = am.getRawParameterType(0);
for (Class<?> expArgType : expArgTypes) {
// And one that matches what we would pass in
if (actualArgType.isAssignableFrom(expArgType)) {
return am.getAnnotated();
}
}
}
}
return null;
}
{
/* First: return<SCANS>
if (instDef != null) {
instantiator = _valueInstantiatorInstance(config, ac, instDef);
}
if (instantiator == null) {
/* Second: see if some of standard Jackson/JDK types might provide value
* instantiators.
*/
instantiator = _findStdValueInstantiator(config, beanDesc);
if (instantiator == null) {
instantiator = _constructDefaultValueInstantiator(ctxt, beanDesc);
}
}
// finally: anyone want to modify ValueInstantiator?
if (_factoryConfig.hasValueInstantiators()) {
for (ValueInstantiators insts : _factoryConfig.valueInstantiators()) {
instantiator = insts.findValueInstantiator(config, beanDesc, instantiator);
// let's do sanity check; easier to spot buggy handlers
if (instantiator == null) {
ctxt.reportMappingException(
"Broken registered ValueInstantiators (of type %s): returned null ValueInstantiator",
insts.getClass().getName());
}
}
}
// Sanity check: does the chosen instantatior have incomplete creators?
if (instantiator.getIncompleteParameter() != null) {
final AnnotatedParameter nonAnnotatedParam = instantiator.getIncompleteParameter();
final AnnotatedWithParams ctor = nonAnnotatedParam.getOwner();
throw new IllegalArgumentException("Argument #"+nonAnnotatedParam.getIndex()+" of constructor "+ctor+" has no property name annotation; must have name when multiple-parameter constructor annotated as Creator");
}
return instantiator;
}
private ValueInstantiator _findStdValueInstantiator(DeserializationConfig config,
BeanDescription beanDesc)
throws JsonMappingException
{
if (beanDesc.getBeanClass() == JsonLocation.class) {
return new JsonLocationInstantiator();
}
return null;
}
/**
* Method that will construct standard default {@link ValueInstantiator}
* using annotations (like @JsonCreator) and visibility rules
*/
protected ValueInstantiator _constructDefaultValueInstantiator(DeserializationContext ctxt,
BeanDescription beanDesc)
throws JsonMappingException
{
CreatorCollector creators = new CreatorCollector(beanDesc, ctxt.getConfig());
AnnotationIntrospector intr = ctxt.getAnnotationIntrospector();
// need to construct suitable visibility checker:
final DeserializationConfig config
JacksonDatabind, 65
<FILEB>
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: (%s) %s",
re.getClass().getName(), re.getMessage());
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
if (isFactoryMethod(am) && am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
if (am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
} else {
return null;
}
return new StdKeyDeserializer(kind, raw);
}
@Override
public Object deserializeKey(String key, DeserializationContext ctxt)
throws IOException
{
if (key == null) { // is this even legal call?
return null;
}
try {
Object result = _parse(key, ctxt);
if (result != null) {
return result;
}
} catch (Exception re) {
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: %s", re.getMessage());
<CHANGEE>
}
if (_keyClass.isEnum() && ctxt.getConfig().isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
return null;
}
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation");
}
public Class<?> getKeyClass() { return _keyClass; }
protected Object _parse(String key, DeserializationContext ctxt) throws Exception
{
switch (_kind) {
case TYPE_BOOLEAN:
if ("true".equals(key)) {
<FILEE>
<FILEB>
*/
if (ac.getParameterCount() == 1) {
Class<?> actArg = ac.getRawParameterType(0);
for (Class<?> expArg : argTypes) {
if (expArg == actArg) {
return ac.getAnnotated();
}
}
}
}
return null;
}
@Override
public Method findFactoryMethod(Class<?>... expArgTypes)
{
// So, of all single-arg static methods:
for (AnnotatedMethod am : _classInfo.getStaticMethods()) {
// 24-Oct-2016, tatu: Better ensure it only takes 1 arg, no matter what
<CHANGES>
if (isFactoryMethod(am)) {
<CHANGEE>
// And must take one of expected arg types (or supertype)
Class<?> actualArgType = am.getRawParameterType(0);
for (Class<?> expArgType : expArgTypes) {
// And one that matches what we would pass in
if (actualArgType.isAssignableFrom(expArgType)) {
return am.getAnnotated();
}
}
}
}
return null;
}
{
/* First: return<SCANS>index] != null) {
throw new IllegalStateException("Conflict: parameter #"+index+" of "+owner
+" bound to more than one property; "+defs[index]+" vs "+propDef);
}
}
defs[index] = propDef;
}
}
return result;
}
public ValueInstantiator _valueInstantiatorInstance(DeserializationConfig config,
Annotated annotated, Object instDef)
throws JsonMappingException
{
if (instDef == null) {
return null;
}
ValueInstantiator inst;
if (instDef instanceof ValueInstantiator) {
return (ValueInstantiator) instDef;
}
if (!(instDef instanceof Class)) {
throw new IllegalStateException("AnnotationIntrospector returned key deserializer definition of type "
+instDef.getClass().getName()
+"; expected type KeyDeserializer or Class<KeyDeserializer> instead");
}
Class<?> instClass = (Class<?>)instDef;
if (ClassUtil.isBogusClass(instClass)) {
return null;
}
if (!ValueInstantiator.class.isAssignableFrom(instClass)) {
throw new IllegalStateException("AnnotationIntrospector returned Class "+instClass.getName()
+"; expected Class<ValueInstantiator>");
}
HandlerInstantiator hi = config.getHandlerInstantiator();
if (hi != null) {
inst = hi.valueInstantiatorInstance(config, annotated, instClass);
if (inst != null) {
return inst;
}
}
return (ValueInstantiator) ClassUtil.createInstance(instClass,
config.canOverrideAccessModifiers());
}
protected void _addDeserializerConstructors
(DeserializationContext ctxt, BeanDescription beanDesc, VisibilityChecker<?> vchecker,
AnnotationIntrospector intr, CreatorCollector creators,
Map<AnnotatedWithParams,BeanPropertyDefinition[]> creatorParams)
throws JsonMappingException
{
// First things first: the "default constructor" (zero-arg
// constructor; whether implicit or explicit) is NOT included
// in list of constructors, so needs to be handled separately.
AnnotatedConstructor defaultCtor = beanDesc.findDefaultConstructor();
if (defaultCtor != null) {
if (!creators.hasDefaultCreator() || intr.hasCreatorAnnotation(defaultCtor)) {
creators.setDefaultCreator(defaultCtor);
}
}
//
JacksonDatabind, 65
<FILEB>
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: (%s) %s",
re.getClass().getName(), re.getMessage());
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
if (isFactoryMethod(am) && am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
if (am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
} else {
return null;
}
return new StdKeyDeserializer(kind, raw);
}
@Override
public Object deserializeKey(String key, DeserializationContext ctxt)
throws IOException
{
if (key == null) { // is this even legal call?
return null;
}
try {
Object result = _parse(key, ctxt);
if (result != null) {
return result;
}
} catch (Exception re) {
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: %s", re.getMessage());
<CHANGEE>
}
if (_keyClass.isEnum() && ctxt.getConfig().isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
return null;
}
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation");
}
public Class<?> getKeyClass() { return _keyClass; }
protected Object _parse(String key, DeserializationContext ctxt) throws Exception
{
switch (_kind) {
case TYPE_BOOLEAN:
if ("true".equals(key)) {
<FILEE>
<FILEB>
*/
if (ac.getParameterCount() == 1) {
Class<?> actArg = ac.getRawParameterType(0);
for (Class<?> expArg : argTypes) {
if (expArg == actArg) {
return ac.getAnnotated();
}
}
}
}
return null;
}
@Override
public Method findFactoryMethod(Class<?>... expArgTypes)
{
// So, of all single-arg static methods:
for (AnnotatedMethod am : _classInfo.getStaticMethods()) {
// 24-Oct-2016, tatu: Better ensure it only takes 1 arg, no matter what
<CHANGES>
if (isFactoryMethod(am)) {
<CHANGEE>
// And must take one of expected arg types (or supertype)
Class<?> actualArgType = am.getRawParameterType(0);
for (Class<?> expArgType : expArgTypes) {
// And one that matches what we would pass in
if (actualArgType.isAssignableFrom(expArgType)) {
return am.getAnnotated();
}
}
}
}
return null;
}
{
/* First: return<SCANS>Override
public CollectionSerializer withResolved(BeanProperty property,
TypeSerializer vts, JsonSerializer<?> elementSerializer,
Boolean unwrapSingle) {
return new CollectionSerializer(this, property, vts, elementSerializer, unwrapSingle);
}
/*
/**********************************************************
/* Accessors
/**********************************************************
*/
@Override
public boolean isEmpty(SerializerProvider prov, Collection<?> value) {
return (value == null) || value.isEmpty();
}
@Override
public boolean hasSingleElement(Collection<?> value) {
Iterator<?> it = value.iterator();
if (!it.hasNext()) {
return false;
}
it.next();
return !it.hasNext();
}
/*
/**********************************************************
/* Actual serialization
/**********************************************************
*/
@Override
public final void serialize(Collection<?> value, JsonGenerator jgen, SerializerProvider provider) throws IOException
{
final int len = value.size();
if (len == 1) {
if (((_unwrapSingle == null) &&
provider.isEnabled(SerializationFeature.WRITE_SINGLE_ELEM_ARRAYS_UNWRAPPED))
|| (_unwrapSingle == Boolean.TRUE)) {
serializeContents(value, jgen, provider);
return;
}
}
jgen.writeStartArray(len);
serializeContents(value, jgen, provider);
jgen.writeEndArray();
}
@Override
public void serializeContents(Collection<?> value, JsonGenerator jgen, SerializerProvider provider) throws IOException
{
if (_elementSerializer != null) {
serializeContentsUsing(value, jgen, provider, _elementSerializer);
return;
}
Iterator<?> it = value.iterator();
if (!it.hasNext()) {
return;
}
PropertySerializerMap serializers = _dynamicSerializers;
final TypeSerializer typeSer = _valueTypeSerializer;
int i = 0;
try {
do {
Object elem = it.next();
if (elem == null) {
provider.defaultSerializeNull(jgen);
} else {
Class<?> cc = elem.getClass();
JsonSerializer<Object> serializer = serializers.serializerFor(cc);
if (serializer == null) {
if (_elementType.hasGenericTypes()) {
serializer = _findAndAddDynamic(serializers,
provider.constructSpecializedType(_elementType, cc), provider);
JacksonDatabind, 65
<FILEB>
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: (%s) %s",
re.getClass().getName(), re.getMessage());
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
if (isFactoryMethod(am) && am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
if (am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
} else {
return null;
}
return new StdKeyDeserializer(kind, raw);
}
@Override
public Object deserializeKey(String key, DeserializationContext ctxt)
throws IOException
{
if (key == null) { // is this even legal call?
return null;
}
try {
Object result = _parse(key, ctxt);
if (result != null) {
return result;
}
} catch (Exception re) {
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: %s", re.getMessage());
<CHANGEE>
}
if (_keyClass.isEnum() && ctxt.getConfig().isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
return null;
}
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation");
}
public Class<?> getKeyClass() { return _keyClass; }
protected Object _parse(String key, DeserializationContext ctxt) throws Exception
{
switch (_kind) {
case TYPE_BOOLEAN:
if ("true".equals(key)) {
<FILEE>
<FILEB>
*/
if (ac.getParameterCount() == 1) {
Class<?> actArg = ac.getRawParameterType(0);
for (Class<?> expArg : argTypes) {
if (expArg == actArg) {
return ac.getAnnotated();
}
}
}
}
return null;
}
@Override
public Method findFactoryMethod(Class<?>... expArgTypes)
{
// So, of all single-arg static methods:
for (AnnotatedMethod am : _classInfo.getStaticMethods()) {
// 24-Oct-2016, tatu: Better ensure it only takes 1 arg, no matter what
<CHANGES>
if (isFactoryMethod(am)) {
<CHANGEE>
// And must take one of expected arg types (or supertype)
Class<?> actualArgType = am.getRawParameterType(0);
for (Class<?> expArgType : expArgTypes) {
// And one that matches what we would pass in
if (actualArgType.isAssignableFrom(expArgType)) {
return am.getAnnotated();
}
}
}
}
return null;
}
{
/* First: return<SCANS>Unknown);
}
protected BeanDeserializer(BeanDeserializerBase src, NameTransformer unwrapper) {
super(src, unwrapper);
}
public BeanDeserializer(BeanDeserializerBase src, ObjectIdReader oir) {
super(src, oir);
}
public BeanDeserializer(BeanDeserializerBase src, Set<String> ignorableProps) {
super(src, ignorableProps);
}
public BeanDeserializer(BeanDeserializerBase src, BeanPropertyMap props) {
super(src, props);
}
@Override
public JsonDeserializer<Object> unwrappingDeserializer(NameTransformer unwrapper)
{
/* bit kludgy but we don't want to accidentally change type; sub-classes
* MUST override this method to support unwrapped properties...
*/
if (getClass() != BeanDeserializer.class) {
return this;
}
/* main thing really is to just enforce ignoring of unknown
* properties; since there may be multiple unwrapped values
* and properties for all may be interleaved...
*/
return new BeanDeserializer(this, unwrapper);
}
@Override
public BeanDeserializer withObjectIdReader(ObjectIdReader oir) {
return new BeanDeserializer(this, oir);
}
@Override
public BeanDeserializer withIgnorableProperties(Set<String> ignorableProps) {
return new BeanDeserializer(this, ignorableProps);
}
@Override
public BeanDeserializerBase withBeanProperties(BeanPropertyMap props) {
return new BeanDeserializer(this, props);
}
@Override
protected BeanDeserializerBase asArrayDeserializer() {
SettableBeanProperty[] props = _beanProperties.getPropertiesInInsertionOrder();
return new BeanAsArrayDeserializer(this, props);
}
/*
/**********************************************************
/* JsonDeserializer implementation
/**********************************************************
*/
/**
* Main deserialization method for bean-based objects (POJOs).
*/
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// common case first
if (p.isExpectedStartObjectToken()) {
if (_vanillaProcessing) {
return vanillaDeserialize(p, ctxt, p.nextToken());
}
// 23-Sep-2015, tatu: This is wrong at some many levels, but for now... it is
// what it is, including "
JacksonDatabind, 65
<FILEB>
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: (%s) %s",
re.getClass().getName(), re.getMessage());
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
if (isFactoryMethod(am) && am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
if (am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
} else {
return null;
}
return new StdKeyDeserializer(kind, raw);
}
@Override
public Object deserializeKey(String key, DeserializationContext ctxt)
throws IOException
{
if (key == null) { // is this even legal call?
return null;
}
try {
Object result = _parse(key, ctxt);
if (result != null) {
return result;
}
} catch (Exception re) {
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: %s", re.getMessage());
<CHANGEE>
}
if (_keyClass.isEnum() && ctxt.getConfig().isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
return null;
}
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation");
}
public Class<?> getKeyClass() { return _keyClass; }
protected Object _parse(String key, DeserializationContext ctxt) throws Exception
{
switch (_kind) {
case TYPE_BOOLEAN:
if ("true".equals(key)) {
<FILEE>
<FILEB>
*/
if (ac.getParameterCount() == 1) {
Class<?> actArg = ac.getRawParameterType(0);
for (Class<?> expArg : argTypes) {
if (expArg == actArg) {
return ac.getAnnotated();
}
}
}
}
return null;
}
@Override
public Method findFactoryMethod(Class<?>... expArgTypes)
{
// So, of all single-arg static methods:
for (AnnotatedMethod am : _classInfo.getStaticMethods()) {
// 24-Oct-2016, tatu: Better ensure it only takes 1 arg, no matter what
<CHANGES>
if (isFactoryMethod(am)) {
<CHANGEE>
// And must take one of expected arg types (or supertype)
Class<?> actualArgType = am.getRawParameterType(0);
for (Class<?> expArgType : expArgTypes) {
// And one that matches what we would pass in
if (actualArgType.isAssignableFrom(expArgType)) {
return am.getAnnotated();
}
}
}
}
return null;
}
{
/* First: return<SCANS>findCreatorProperty(propName);
if (creatorProp != null) {
// Last creator property to set?
if (buffer.assignParameter(creatorProp,
_deserializeWithErrorWrapping(p, ctxt, creatorProp))) {
p.nextToken(); // to move to following FIELD_NAME/END_OBJECT
Object bean;
try {
bean = creator.build(ctxt, buffer);
} catch (Exception e) {
bean = wrapInstantiationProblem(e, ctxt);
}
if (bean == null) {
return ctxt.handleInstantiationProblem(handledType(), null,
_creatorReturnedNullException());
}
// [databind#631]: Assign current value, to be accessible by custom serializers
p.setCurrentValue(bean);
// polymorphic?
if (bean.getClass() != _beanType.getRawClass()) {
return handlePolymorphic(p, ctxt, bean, unknown);
}
if (unknown != null) { // nope, just extra unknown stuff...
bean = handleUnknownProperties(ctxt, bean, unknown);
}
// or just clean?
return deserialize(p, ctxt, bean);
}
continue;
}
// Object Id property?
if (buffer.readIdProperty(propName)) {
continue;
}
// regular property? needs buffering
SettableBeanProperty prop = _beanProperties.find(propName);
if (prop != null) {
try {
buffer.bufferProperty(prop, _deserializeWithErrorWrapping(p, ctxt, prop));
} catch (UnresolvedForwardReference reference) {
// 14-Jun-2016, tatu: As per [databind#1261], looks like we need additional
// handling of forward references here. Not exactly sure why existing
// facilities did not cover, but this does appear to solve the problem
BeanReferring referring = handleUnresolvedReference(ctxt,
prop, buffer, reference);
if (referrings == null) {
referrings = new ArrayList<BeanReferring>();
}
referrings.add(referring);
}
continue;
}
// Things marked as ignorable should not be passed to any setter
if (_ignorableProps != null && _ignorableProps.contains(propName)) {
handleIgnoredProperty(p, ctxt
JacksonDatabind, 65
<FILEB>
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: (%s) %s",
re.getClass().getName(), re.getMessage());
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
if (isFactoryMethod(am) && am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
if (am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
} else {
return null;
}
return new StdKeyDeserializer(kind, raw);
}
@Override
public Object deserializeKey(String key, DeserializationContext ctxt)
throws IOException
{
if (key == null) { // is this even legal call?
return null;
}
try {
Object result = _parse(key, ctxt);
if (result != null) {
return result;
}
} catch (Exception re) {
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: %s", re.getMessage());
<CHANGEE>
}
if (_keyClass.isEnum() && ctxt.getConfig().isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
return null;
}
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation");
}
public Class<?> getKeyClass() { return _keyClass; }
protected Object _parse(String key, DeserializationContext ctxt) throws Exception
{
switch (_kind) {
case TYPE_BOOLEAN:
if ("true".equals(key)) {
<FILEE>
<FILEB>
*/
if (ac.getParameterCount() == 1) {
Class<?> actArg = ac.getRawParameterType(0);
for (Class<?> expArg : argTypes) {
if (expArg == actArg) {
return ac.getAnnotated();
}
}
}
}
return null;
}
@Override
public Method findFactoryMethod(Class<?>... expArgTypes)
{
// So, of all single-arg static methods:
for (AnnotatedMethod am : _classInfo.getStaticMethods()) {
// 24-Oct-2016, tatu: Better ensure it only takes 1 arg, no matter what
<CHANGES>
if (isFactoryMethod(am)) {
<CHANGEE>
// And must take one of expected arg types (or supertype)
Class<?> actualArgType = am.getRawParameterType(0);
for (Class<?> expArgType : expArgTypes) {
// And one that matches what we would pass in
if (actualArgType.isAssignableFrom(expArgType)) {
return am.getAnnotated();
}
}
}
}
return null;
}
{
/* First: return<SCANS>, handledType(), propName);
continue;
}
// "any property"?
if (_anySetter != null) {
try {
buffer.bufferAnyProperty(_anySetter, propName, _anySetter.deserialize(p, ctxt));
} catch (Exception e) {
wrapAndThrow(e, _beanType.getRawClass(), propName, ctxt);
}
continue;
}
// Ok then, let's collect the whole field; name and value
if (unknown == null) {
unknown = new TokenBuffer(p, ctxt);
}
unknown.writeFieldName(propName);
unknown.copyCurrentStructure(p);
}
// We hit END_OBJECT, so:
Object bean;
try {
bean = creator.build(ctxt, buffer);
} catch (Exception e) {
wrapInstantiationProblem(e, ctxt);
bean = null; // never gets here
}
if (referrings != null) {
for (BeanReferring referring : referrings) {
referring.setBean(bean);
}
}
if (unknown != null) {
// polymorphic?
if (bean.getClass() != _beanType.getRawClass()) {
return handlePolymorphic(null, ctxt, bean, unknown);
}
// no, just some extra unknown properties
return handleUnknownProperties(ctxt, bean, unknown);
}
return bean;
}
/**
* @since 2.8
*/
private BeanReferring handleUnresolvedReference(DeserializationContext ctxt,
SettableBeanProperty prop, PropertyValueBuffer buffer,
UnresolvedForwardReference reference)
throws JsonMappingException
{
BeanReferring referring = new BeanReferring(ctxt, reference,
prop.getType(), buffer, prop);
reference.getRoid().appendReferring(referring);
return referring;
}
protected final Object _deserializeWithErrorWrapping(JsonParser p,
DeserializationContext ctxt, SettableBeanProperty prop)
throws IOException
{
try {
return prop.deserialize(p, ctxt);
} catch (Exception e) {
wrapAndThrow(e, _beanType.getRawClass(), prop.getName(), ctxt);
// never gets here, unless caller declines to throw an exception
return null;
}
}
/**
* Helper method called for rare case of
JacksonDatabind, 65
<FILEB>
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: (%s) %s",
re.getClass().getName(), re.getMessage());
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
if (isFactoryMethod(am) && am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
if (am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
} else {
return null;
}
return new StdKeyDeserializer(kind, raw);
}
@Override
public Object deserializeKey(String key, DeserializationContext ctxt)
throws IOException
{
if (key == null) { // is this even legal call?
return null;
}
try {
Object result = _parse(key, ctxt);
if (result != null) {
return result;
}
} catch (Exception re) {
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: %s", re.getMessage());
<CHANGEE>
}
if (_keyClass.isEnum() && ctxt.getConfig().isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
return null;
}
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation");
}
public Class<?> getKeyClass() { return _keyClass; }
protected Object _parse(String key, DeserializationContext ctxt) throws Exception
{
switch (_kind) {
case TYPE_BOOLEAN:
if ("true".equals(key)) {
<FILEE>
<FILEB>
*/
if (ac.getParameterCount() == 1) {
Class<?> actArg = ac.getRawParameterType(0);
for (Class<?> expArg : argTypes) {
if (expArg == actArg) {
return ac.getAnnotated();
}
}
}
}
return null;
}
@Override
public Method findFactoryMethod(Class<?>... expArgTypes)
{
// So, of all single-arg static methods:
for (AnnotatedMethod am : _classInfo.getStaticMethods()) {
// 24-Oct-2016, tatu: Better ensure it only takes 1 arg, no matter what
<CHANGES>
if (isFactoryMethod(am)) {
<CHANGEE>
// And must take one of expected arg types (or supertype)
Class<?> actualArgType = am.getRawParameterType(0);
for (Class<?> expArgType : expArgTypes) {
// And one that matches what we would pass in
if (actualArgType.isAssignableFrom(expArgType)) {
return am.getAnnotated();
}
}
}
}
return null;
}
{
/* First: return<SCANS>UsingPropertyBasedWithUnwrapped(JsonParser p, DeserializationContext ctxt)
throws IOException
{
final PropertyBasedCreator creator = _propertyBasedCreator;
PropertyValueBuffer buffer = creator.startBuilding(p, ctxt, _objectIdReader);
TokenBuffer tokens = new TokenBuffer(p, ctxt);
tokens.writeStartObject();
JsonToken t = p.getCurrentToken();
for (; t == JsonToken.FIELD_NAME; t = p.nextToken()) {
String propName = p.getCurrentName();
p.nextToken(); // to point to value
// creator property?
SettableBeanProperty creatorProp = creator.findCreatorProperty(propName);
if (creatorProp != null) {
// Last creator property to set?
if (buffer.assignParameter(creatorProp, _deserializeWithErrorWrapping(p, ctxt, creatorProp))) {
t = p.nextToken(); // to move to following FIELD_NAME/END_OBJECT
Object bean;
try {
bean = creator.build(ctxt, buffer);
} catch (Exception e) {
bean = wrapInstantiationProblem(e, ctxt);
}
// [databind#631]: Assign current value, to be accessible by custom serializers
p.setCurrentValue(bean);
// if so, need to copy all remaining tokens into buffer
while (t == JsonToken.FIELD_NAME) {
p.nextToken(); // to skip name
tokens.copyCurrentStructure(p);
t = p.nextToken();
}
tokens.writeEndObject();
if (bean.getClass() != _beanType.getRawClass()) {
// !!! 08-Jul-2011, tatu: Could probably support; but for now
// it's too complicated, so bail out
tokens.close();
ctxt.reportMappingException("Can not create polymorphic instances with unwrapped values");
return null;
}
return _unwrappedPropertyHandler.processUnwrapped(p, ctxt, bean, tokens);
}
continue;
}
// Object Id property?
if (buffer.readIdProperty(propName)) {
continue;
}
// regular property? needs buffering
SettableBeanProperty prop = _beanProperties.find(propName);
if (prop != null) {
buffer.bufferProperty(prop, _deserializeWithErrorWrapping(p,
JacksonDatabind, 65
<FILEB>
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: (%s) %s",
re.getClass().getName(), re.getMessage());
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
if (isFactoryMethod(am) && am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
if (am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
} else {
return null;
}
return new StdKeyDeserializer(kind, raw);
}
@Override
public Object deserializeKey(String key, DeserializationContext ctxt)
throws IOException
{
if (key == null) { // is this even legal call?
return null;
}
try {
Object result = _parse(key, ctxt);
if (result != null) {
return result;
}
} catch (Exception re) {
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: %s", re.getMessage());
<CHANGEE>
}
if (_keyClass.isEnum() && ctxt.getConfig().isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
return null;
}
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation");
}
public Class<?> getKeyClass() { return _keyClass; }
protected Object _parse(String key, DeserializationContext ctxt) throws Exception
{
switch (_kind) {
case TYPE_BOOLEAN:
if ("true".equals(key)) {
<FILEE>
<FILEB>
*/
if (ac.getParameterCount() == 1) {
Class<?> actArg = ac.getRawParameterType(0);
for (Class<?> expArg : argTypes) {
if (expArg == actArg) {
return ac.getAnnotated();
}
}
}
}
return null;
}
@Override
public Method findFactoryMethod(Class<?>... expArgTypes)
{
// So, of all single-arg static methods:
for (AnnotatedMethod am : _classInfo.getStaticMethods()) {
// 24-Oct-2016, tatu: Better ensure it only takes 1 arg, no matter what
<CHANGES>
if (isFactoryMethod(am)) {
<CHANGEE>
// And must take one of expected arg types (or supertype)
Class<?> actualArgType = am.getRawParameterType(0);
for (Class<?> expArgType : expArgTypes) {
// And one that matches what we would pass in
if (actualArgType.isAssignableFrom(expArgType)) {
return am.getAnnotated();
}
}
}
}
return null;
}
{
/* First: return<SCANS>Token t = p.getCurrentToken();
for (; t == JsonToken.FIELD_NAME; t = p.nextToken()) {
String propName = p.getCurrentName();
p.nextToken(); // to point to value
// creator property?
SettableBeanProperty creatorProp = creator.findCreatorProperty(propName);
if (creatorProp != null) {
// first: let's check to see if this might be part of value with external type id:
// 11-Sep-2015, tatu: Important; do NOT pass buffer as last arg, but null,
// since it is not the bean
if (ext.handlePropertyValue(p, ctxt, propName, null)) {
;
} else {
// Last creator property to set?
if (buffer.assignParameter(creatorProp, _deserializeWithErrorWrapping(p, ctxt, creatorProp))) {
t = p.nextToken(); // to move to following FIELD_NAME/END_OBJECT
Object bean;
try {
bean = creator.build(ctxt, buffer);
} catch (Exception e) {
wrapAndThrow(e, _beanType.getRawClass(), propName, ctxt);
continue; // never gets here
}
// if so, need to copy all remaining tokens into buffer
while (t == JsonToken.FIELD_NAME) {
p.nextToken(); // to skip name
tokens.copyCurrentStructure(p);
t = p.nextToken();
}
if (bean.getClass() != _beanType.getRawClass()) {
// !!! 08-Jul-2011, tatu: Could theoretically support; but for now
// it's too complicated, so bail out
ctxt.reportMappingException("Can not create polymorphic instances with external type ids");
return null;
}
return ext.complete(p, ctxt, bean);
}
}
continue;
}
// Object Id property?
if (buffer.readIdProperty(propName)) {
continue;
}
// regular property? needs buffering
SettableBeanProperty prop = _beanProperties.find(propName);
if (prop != null) {
buffer.bufferProperty(prop, prop.deserialize(p, ctxt));
continue;
}
// external type id (or property that depends on it)?
JacksonDatabind, 65
<FILEB>
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: (%s) %s",
re.getClass().getName(), re.getMessage());
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
if (isFactoryMethod(am) && am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
if (am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
} else {
return null;
}
return new StdKeyDeserializer(kind, raw);
}
@Override
public Object deserializeKey(String key, DeserializationContext ctxt)
throws IOException
{
if (key == null) { // is this even legal call?
return null;
}
try {
Object result = _parse(key, ctxt);
if (result != null) {
return result;
}
} catch (Exception re) {
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: %s", re.getMessage());
<CHANGEE>
}
if (_keyClass.isEnum() && ctxt.getConfig().isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
return null;
}
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation");
}
public Class<?> getKeyClass() { return _keyClass; }
protected Object _parse(String key, DeserializationContext ctxt) throws Exception
{
switch (_kind) {
case TYPE_BOOLEAN:
if ("true".equals(key)) {
<FILEE>
<FILEB>
*/
if (ac.getParameterCount() == 1) {
Class<?> actArg = ac.getRawParameterType(0);
for (Class<?> expArg : argTypes) {
if (expArg == actArg) {
return ac.getAnnotated();
}
}
}
}
return null;
}
@Override
public Method findFactoryMethod(Class<?>... expArgTypes)
{
// So, of all single-arg static methods:
for (AnnotatedMethod am : _classInfo.getStaticMethods()) {
// 24-Oct-2016, tatu: Better ensure it only takes 1 arg, no matter what
<CHANGES>
if (isFactoryMethod(am)) {
<CHANGEE>
// And must take one of expected arg types (or supertype)
Class<?> actualArgType = am.getRawParameterType(0);
for (Class<?> expArgType : expArgTypes) {
// And one that matches what we would pass in
if (actualArgType.isAssignableFrom(expArgType)) {
return am.getAnnotated();
}
}
}
}
return null;
}
{
/* First: return<SCANS>package com.fasterxml.jackson.databind;
import java.io.IOException;
import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.core.format.InputAccessor;
import com.fasterxml.jackson.core.format.MatchStrength;
/**
* Sub-class of {@link JsonFactory} that will create a proper
* {@link ObjectCodec} to allow seam-less conversions between
* JSON content and Java objects (POJOs).
* The only addition to regular {@link JsonFactory} currently
* is that {@link ObjectMapper} is constructed and passed as
* the codec to use.
*/
public class MappingJsonFactory
extends JsonFactory
{
private static final long serialVersionUID = -1; // since 2.7
public MappingJsonFactory()
{
this(null);
}
public MappingJsonFactory(ObjectMapper mapper)
{
super(mapper);
if (mapper == null) {
setCodec(new ObjectMapper(this));
}
}
public MappingJsonFactory(JsonFactory src, ObjectMapper mapper)
{
super(src, mapper);
if (mapper == null) {
setCodec(new ObjectMapper(this));
}
}
/**
* We'll override the method to return more specific type; co-variance
* helps here
*/
@Override
public final ObjectMapper getCodec() { return (ObjectMapper) _objectCodec; }
// @since 2.1
@Override
public JsonFactory copy()
{
_checkInvalidCopy(MappingJsonFactory.class);
// note: as with base class, must NOT copy mapper reference
return new MappingJsonFactory(this, null);
}
/*
/**********************************************************
/* Format detection functionality (since 1.8)
/**********************************************************
*/
/**
* Sub-classes need to override this method
*/
@Override
public String getFormatName()
{
/* since non-JSON factories typically should not extend this class,
* let's just always return JSON as name.
*/
return FORMAT_NAME_JSON;
}
/**
* Sub-classes need to override this method
*/
@Override
public MatchStrength hasFormat(InputAccessor acc) throws IOException
{
if (getClass() == MappingJsonFactory.class) {
return hasJSONFormat(acc);
}
return null;
JacksonDatabind, 65
<FILEB>
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: (%s) %s",
re.getClass().getName(), re.getMessage());
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
if (isFactoryMethod(am) && am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
if (am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
} else {
return null;
}
return new StdKeyDeserializer(kind, raw);
}
@Override
public Object deserializeKey(String key, DeserializationContext ctxt)
throws IOException
{
if (key == null) { // is this even legal call?
return null;
}
try {
Object result = _parse(key, ctxt);
if (result != null) {
return result;
}
} catch (Exception re) {
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: %s", re.getMessage());
<CHANGEE>
}
if (_keyClass.isEnum() && ctxt.getConfig().isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
return null;
}
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation");
}
public Class<?> getKeyClass() { return _keyClass; }
protected Object _parse(String key, DeserializationContext ctxt) throws Exception
{
switch (_kind) {
case TYPE_BOOLEAN:
if ("true".equals(key)) {
<FILEE>
<FILEB>
*/
if (ac.getParameterCount() == 1) {
Class<?> actArg = ac.getRawParameterType(0);
for (Class<?> expArg : argTypes) {
if (expArg == actArg) {
return ac.getAnnotated();
}
}
}
}
return null;
}
@Override
public Method findFactoryMethod(Class<?>... expArgTypes)
{
// So, of all single-arg static methods:
for (AnnotatedMethod am : _classInfo.getStaticMethods()) {
// 24-Oct-2016, tatu: Better ensure it only takes 1 arg, no matter what
<CHANGES>
if (isFactoryMethod(am)) {
<CHANGEE>
// And must take one of expected arg types (or supertype)
Class<?> actualArgType = am.getRawParameterType(0);
for (Class<?> expArgType : expArgTypes) {
// And one that matches what we would pass in
if (actualArgType.isAssignableFrom(expArgType)) {
return am.getAnnotated();
}
}
}
}
return null;
}
{
/* First: return<SCANS>
Type[] types = _constructor.getGenericParameterTypes();
if (index >= types.length) {
return null;
}
return _typeContext.resolveType(types[index]);
}
@Override
@Deprecated // since 2.7
public Type getGenericParameterType(int index) {
Type[] types = _constructor.getGenericParameterTypes();
if (index >= types.length) {
return null;
}
return types[index];
}
@Override
public final Object call() throws Exception {
return _constructor.newInstance();
}
@Override
public final Object call(Object[] args) throws Exception {
return _constructor.newInstance(args);
}
@Override
public final Object call1(Object arg) throws Exception {
return _constructor.newInstance(arg);
}
/*
/**********************************************************
/* AnnotatedMember impl
/**********************************************************
*/
@Override
public Class<?> getDeclaringClass() { return _constructor.getDeclaringClass(); }
@Override
public Member getMember() { return _constructor; }
@Override
public void setValue(Object pojo, Object value)
throws UnsupportedOperationException
{
throw new UnsupportedOperationException("Cannot call setValue() on constructor of "
+getDeclaringClass().getName());
}
@Override
public Object getValue(Object pojo)
throws UnsupportedOperationException
{
throw new UnsupportedOperationException("Cannot call getValue() on constructor of "
+getDeclaringClass().getName());
}
/*
/**********************************************************
/* Extended API, specific annotations
/**********************************************************
*/
@Override
public String toString() {
return "[constructor for "+getName()+", annotations: "+_annotations+"]";
}
@Override
public int hashCode() {
return _constructor.getName().hashCode();
}
@Override
public boolean equals(Object o) {
if (o == this) return true;
if (o == null || o.getClass() != getClass()) return false;
return ((AnnotatedConstructor) o)._constructor == _constructor;
}
/*
/**********************************************************
/* JDK serialization handling
/**********************************************************
*/
Object writeReplace() {
return new AnnotatedConstructor(new Serialization(_constructor));
}
Object readResolve() {
Class<?> clazz = _serialization.clazz;
try {
Constructor<?> ctor = clazz.getDeclaredConstructor(_serialization.
JacksonDatabind, 65
<FILEB>
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: (%s) %s",
re.getClass().getName(), re.getMessage());
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
if (isFactoryMethod(am) && am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
if (am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
} else {
return null;
}
return new StdKeyDeserializer(kind, raw);
}
@Override
public Object deserializeKey(String key, DeserializationContext ctxt)
throws IOException
{
if (key == null) { // is this even legal call?
return null;
}
try {
Object result = _parse(key, ctxt);
if (result != null) {
return result;
}
} catch (Exception re) {
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: %s", re.getMessage());
<CHANGEE>
}
if (_keyClass.isEnum() && ctxt.getConfig().isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
return null;
}
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation");
}
public Class<?> getKeyClass() { return _keyClass; }
protected Object _parse(String key, DeserializationContext ctxt) throws Exception
{
switch (_kind) {
case TYPE_BOOLEAN:
if ("true".equals(key)) {
<FILEE>
<FILEB>
*/
if (ac.getParameterCount() == 1) {
Class<?> actArg = ac.getRawParameterType(0);
for (Class<?> expArg : argTypes) {
if (expArg == actArg) {
return ac.getAnnotated();
}
}
}
}
return null;
}
@Override
public Method findFactoryMethod(Class<?>... expArgTypes)
{
// So, of all single-arg static methods:
for (AnnotatedMethod am : _classInfo.getStaticMethods()) {
// 24-Oct-2016, tatu: Better ensure it only takes 1 arg, no matter what
<CHANGES>
if (isFactoryMethod(am)) {
<CHANGEE>
// And must take one of expected arg types (or supertype)
Class<?> actualArgType = am.getRawParameterType(0);
for (Class<?> expArgType : expArgTypes) {
// And one that matches what we would pass in
if (actualArgType.isAssignableFrom(expArgType)) {
return am.getAnnotated();
}
}
}
}
return null;
}
{
/* First: return<SCANS>config.constructType(value.getClass());
} else {
t = _valueType;
}
return _new(this, _config, t, _rootDeserializer, value,
_schema, _injectableValues, _dataFormatReaders);
}
/**
* Method for constructing a new instance with configuration that
* uses specified View for filtering.
*<p>
* Note that the method does NOT change state of this reader, but
* rather construct and returns a newly configured instance.
*/
public ObjectReader withView(Class<?> activeView) {
return _with(_config.withView(activeView));
}
public ObjectReader with(Locale l) {
return _with(_config.with(l));
}
public ObjectReader with(TimeZone tz) {
return _with(_config.with(tz));
}
public ObjectReader withHandler(DeserializationProblemHandler h) {
return _with(_config.withHandler(h));
}
public ObjectReader with(Base64Variant defaultBase64) {
return _with(_config.with(defaultBase64));
}
/**
* Fluent factory method for constructing a reader that will try to
* auto-detect underlying data format, using specified list of
* {@link JsonFactory} instances, and default {@link DataFormatReaders} settings
* (for customized {@link DataFormatReaders}, you can construct instance yourself).
* to construct appropriate {@link JsonParser} for actual parsing.
*<p>
* Note: since format detection only works with byte sources, it is possible to
* get a failure from some 'readValue()' methods. Also, if input can not be reliably
* (enough) detected as one of specified types, an exception will be thrown.
*<p>
* Note: not all {@link JsonFactory} types can be passed: specifically, ones that
* require "custom codec" (like XML factory) will not work. Instead, use
* method that takes {@link ObjectReader} instances instead of factories.
*
* @param readers Data formats accepted, in decreasing order of priority (that is,
* matches checked in listed order, first match wins)
*
* @return Newly configured writer instance
*
* @since 2.1
*/
public ObjectReader withFormatDetection(Object
JacksonDatabind, 65
<FILEB>
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: (%s) %s",
re.getClass().getName(), re.getMessage());
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
if (isFactoryMethod(am) && am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
if (am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
} else {
return null;
}
return new StdKeyDeserializer(kind, raw);
}
@Override
public Object deserializeKey(String key, DeserializationContext ctxt)
throws IOException
{
if (key == null) { // is this even legal call?
return null;
}
try {
Object result = _parse(key, ctxt);
if (result != null) {
return result;
}
} catch (Exception re) {
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: %s", re.getMessage());
<CHANGEE>
}
if (_keyClass.isEnum() && ctxt.getConfig().isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
return null;
}
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation");
}
public Class<?> getKeyClass() { return _keyClass; }
protected Object _parse(String key, DeserializationContext ctxt) throws Exception
{
switch (_kind) {
case TYPE_BOOLEAN:
if ("true".equals(key)) {
<FILEE>
<FILEB>
*/
if (ac.getParameterCount() == 1) {
Class<?> actArg = ac.getRawParameterType(0);
for (Class<?> expArg : argTypes) {
if (expArg == actArg) {
return ac.getAnnotated();
}
}
}
}
return null;
}
@Override
public Method findFactoryMethod(Class<?>... expArgTypes)
{
// So, of all single-arg static methods:
for (AnnotatedMethod am : _classInfo.getStaticMethods()) {
// 24-Oct-2016, tatu: Better ensure it only takes 1 arg, no matter what
<CHANGES>
if (isFactoryMethod(am)) {
<CHANGEE>
// And must take one of expected arg types (or supertype)
Class<?> actualArgType = am.getRawParameterType(0);
for (Class<?> expArgType : expArgTypes) {
// And one that matches what we would pass in
if (actualArgType.isAssignableFrom(expArgType)) {
return am.getAnnotated();
}
}
}
}
return null;
}
{
/* First: return<SCANS>Match()) {
_reportUnkownFormat(_dataFormatReaders, match);
}
JsonParser p = match.createParserWithMatch();
// One more thing: we Own the input stream now; and while it's
// not super clean way to do it, we must ensure closure so:
if (forceClosing) {
p.enable(JsonParser.Feature.AUTO_CLOSE_SOURCE);
}
// important: use matching ObjectReader (may not be 'this')
return match.getReader()._bindAndReadValues(p);
}
@SuppressWarnings("resource")
protected JsonNode _detectBindAndCloseAsTree(InputStream in) throws IOException
{
DataFormatReaders.Match match = _dataFormatReaders.findFormat(in);
if (!match.hasMatch()) {
_reportUnkownFormat(_dataFormatReaders, match);
}
JsonParser p = match.createParserWithMatch();
p.enable(JsonParser.Feature.AUTO_CLOSE_SOURCE);
return match.getReader()._bindAndCloseAsTree(p);
}
/**
* Method called to indicate that format detection failed to detect format
* of given input
*/
protected void _reportUnkownFormat(DataFormatReaders detector, DataFormatReaders.Match match) throws JsonProcessingException
{
// 17-Aug-2015, tatu: Unfortunately, no parser/generator available so:
throw new JsonParseException(null, "Can not detect format from input, does not look like any of detectable formats "
+detector.toString());
}
/*
/**********************************************************
/* Internal methods, other
/**********************************************************
*/
/**
* @since 2.2
*/
protected void _verifySchemaType(FormatSchema schema)
{
if (schema != null) {
if (!_parserFactory.canUseSchema(schema)) {
throw new IllegalArgumentException("Can not use FormatSchema of type "+schema.getClass().getName()
+" for format "+_parserFactory.getFormatName());
}
}
}
/**
* Internal helper method called to create an instance of {@link DeserializationContext}
* for deserializing a single root value.
* Can be overridden if a custom context is needed.
*/
protected DefaultDeserializationContext createDeserializationContext(JsonParser p) {
JacksonDatabind, 65
<FILEB>
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: (%s) %s",
re.getClass().getName(), re.getMessage());
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
if (isFactoryMethod(am) && am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
if (am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
} else {
return null;
}
return new StdKeyDeserializer(kind, raw);
}
@Override
public Object deserializeKey(String key, DeserializationContext ctxt)
throws IOException
{
if (key == null) { // is this even legal call?
return null;
}
try {
Object result = _parse(key, ctxt);
if (result != null) {
return result;
}
} catch (Exception re) {
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: %s", re.getMessage());
<CHANGEE>
}
if (_keyClass.isEnum() && ctxt.getConfig().isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
return null;
}
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation");
}
public Class<?> getKeyClass() { return _keyClass; }
protected Object _parse(String key, DeserializationContext ctxt) throws Exception
{
switch (_kind) {
case TYPE_BOOLEAN:
if ("true".equals(key)) {
<FILEE>
<FILEB>
*/
if (ac.getParameterCount() == 1) {
Class<?> actArg = ac.getRawParameterType(0);
for (Class<?> expArg : argTypes) {
if (expArg == actArg) {
return ac.getAnnotated();
}
}
}
}
return null;
}
@Override
public Method findFactoryMethod(Class<?>... expArgTypes)
{
// So, of all single-arg static methods:
for (AnnotatedMethod am : _classInfo.getStaticMethods()) {
// 24-Oct-2016, tatu: Better ensure it only takes 1 arg, no matter what
<CHANGES>
if (isFactoryMethod(am)) {
<CHANGEE>
// And must take one of expected arg types (or supertype)
Class<?> actualArgType = am.getRawParameterType(0);
for (Class<?> expArgType : expArgTypes) {
// And one that matches what we would pass in
if (actualArgType.isAssignableFrom(expArgType)) {
return am.getAnnotated();
}
}
}
}
return null;
}
{
/* First: return<SCANS>
return _context.createInstance(_config, p, _injectableValues);
}
protected void _reportUndetectableSource(Object src) throws JsonProcessingException
{
// 17-Aug-2015, tatu: Unfortunately, no parser/generator available so:
throw new JsonParseException(null, "Can not use source of type "
+src.getClass().getName()+" with format auto-detection: must be byte- not char-based");
}
protected InputStream _inputStream(URL src) throws IOException {
return src.openStream();
}
protected InputStream _inputStream(File f) throws IOException {
return new FileInputStream(f);
}
/*
/**********************************************************
/* Helper methods, locating deserializers etc
/**********************************************************
*/
/**
* Method called to locate deserializer for the passed root-level value.
*/
protected JsonDeserializer<Object> _findRootDeserializer(DeserializationContext ctxt)
throws JsonMappingException
{
if (_rootDeserializer != null) {
return _rootDeserializer;
}
// Sanity check: must have actual type...
JavaType t = _valueType;
if (t == null) {
ctxt.reportMappingException("No value type configured for ObjectReader");
}
// First: have we already seen it?
JsonDeserializer<Object> deser = _rootDeserializers.get(t);
if (deser != null) {
return deser;
}
// Nope: need to ask provider to resolve it
deser = ctxt.findRootValueDeserializer(t);
if (deser == null) { // can this happen?
ctxt.reportMappingException("Can not find a deserializer for type %s", t);
}
_rootDeserializers.put(t, deser);
return deser;
}
/**
* @since 2.6
*/
protected JsonDeserializer<Object> _findTreeDeserializer(DeserializationContext ctxt)
throws JsonMappingException
{
JsonDeserializer<Object> deser = _rootDeserializers.get(JSON_NODE_TYPE);
if (deser == null) {
// Nope: need to ask provider to resolve it
deser = ctxt.findRootValueDeserializer(JSON_NODE_TYPE);
if (deser == null) { // can this happen?
ctxt.reportMappingException("Can not find
JacksonDatabind, 65
<FILEB>
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: (%s) %s",
re.getClass().getName(), re.getMessage());
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
if (isFactoryMethod(am) && am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
if (am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
} else {
return null;
}
return new StdKeyDeserializer(kind, raw);
}
@Override
public Object deserializeKey(String key, DeserializationContext ctxt)
throws IOException
{
if (key == null) { // is this even legal call?
return null;
}
try {
Object result = _parse(key, ctxt);
if (result != null) {
return result;
}
} catch (Exception re) {
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: %s", re.getMessage());
<CHANGEE>
}
if (_keyClass.isEnum() && ctxt.getConfig().isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
return null;
}
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation");
}
public Class<?> getKeyClass() { return _keyClass; }
protected Object _parse(String key, DeserializationContext ctxt) throws Exception
{
switch (_kind) {
case TYPE_BOOLEAN:
if ("true".equals(key)) {
<FILEE>
<FILEB>
*/
if (ac.getParameterCount() == 1) {
Class<?> actArg = ac.getRawParameterType(0);
for (Class<?> expArg : argTypes) {
if (expArg == actArg) {
return ac.getAnnotated();
}
}
}
}
return null;
}
@Override
public Method findFactoryMethod(Class<?>... expArgTypes)
{
// So, of all single-arg static methods:
for (AnnotatedMethod am : _classInfo.getStaticMethods()) {
// 24-Oct-2016, tatu: Better ensure it only takes 1 arg, no matter what
<CHANGES>
if (isFactoryMethod(am)) {
<CHANGEE>
// And must take one of expected arg types (or supertype)
Class<?> actualArgType = am.getRawParameterType(0);
for (Class<?> expArgType : expArgTypes) {
// And one that matches what we would pass in
if (actualArgType.isAssignableFrom(expArgType)) {
return am.getAnnotated();
}
}
}
}
return null;
}
{
/* First: return<SCANS> throws JsonMappingException
{
JsonSerializer<?> ser = _valueSerializer;
if (ser == null) {
/* Can only assign serializer statically if the declared type is final:
* if not, we don't really know the actual type until we get the instance.
*/
// 10-Mar-2010, tatu: Except if static typing is to be used
JavaType t = _accessorMethod.getType();
if (provider.isEnabled(MapperFeature.USE_STATIC_TYPING) || t.isFinal()) {
// false -> no need to cache
/* 10-Mar-2010, tatu: Ideally we would actually separate out type
* serializer from value serializer; but, alas, there's no access
* to serializer factory at this point...
*/
// 05-Sep-2013, tatu: I _think_ this can be considered a primary property...
ser = provider.findPrimaryPropertySerializer(t, property);
/* 09-Dec-2010, tatu: Turns out we must add special handling for
* cases where "native" (aka "natural") type is being serialized,
* using standard serializer
*/
boolean forceTypeInformation = isNaturalTypeWithStdHandling(t.getRawClass(), ser);
return withResolved(property, ser, forceTypeInformation);
}
} else {
// 05-Sep-2013, tatu: I _think_ this can be considered a primary property...
ser = provider.handlePrimaryContextualization(ser, property);
return withResolved(property, ser, _forceTypeInformation);
}
return this;
}
/*
/**********************************************************
/* Actual serialization
/**********************************************************
*/
@Override
public void serialize(Object bean, JsonGenerator gen, SerializerProvider prov) throws IOException
{
try {
Object value = _accessorMethod.getValue(bean);
if (value == null) {
prov.defaultSerializeNull(gen);
return;
}
JsonSerializer<Object> ser = _valueSerializer;
if (ser == null) {
Class<?> c = value.getClass();
/* 10-Mar-2010, tatu: Ideally we would actually separate out type
* serializer from
JacksonDatabind, 65
<FILEB>
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: (%s) %s",
re.getClass().getName(), re.getMessage());
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
if (isFactoryMethod(am) && am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
if (am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
} else {
return null;
}
return new StdKeyDeserializer(kind, raw);
}
@Override
public Object deserializeKey(String key, DeserializationContext ctxt)
throws IOException
{
if (key == null) { // is this even legal call?
return null;
}
try {
Object result = _parse(key, ctxt);
if (result != null) {
return result;
}
} catch (Exception re) {
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: %s", re.getMessage());
<CHANGEE>
}
if (_keyClass.isEnum() && ctxt.getConfig().isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
return null;
}
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation");
}
public Class<?> getKeyClass() { return _keyClass; }
protected Object _parse(String key, DeserializationContext ctxt) throws Exception
{
switch (_kind) {
case TYPE_BOOLEAN:
if ("true".equals(key)) {
<FILEE>
<FILEB>
*/
if (ac.getParameterCount() == 1) {
Class<?> actArg = ac.getRawParameterType(0);
for (Class<?> expArg : argTypes) {
if (expArg == actArg) {
return ac.getAnnotated();
}
}
}
}
return null;
}
@Override
public Method findFactoryMethod(Class<?>... expArgTypes)
{
// So, of all single-arg static methods:
for (AnnotatedMethod am : _classInfo.getStaticMethods()) {
// 24-Oct-2016, tatu: Better ensure it only takes 1 arg, no matter what
<CHANGES>
if (isFactoryMethod(am)) {
<CHANGEE>
// And must take one of expected arg types (or supertype)
Class<?> actualArgType = am.getRawParameterType(0);
for (Class<?> expArgType : expArgTypes) {
// And one that matches what we would pass in
if (actualArgType.isAssignableFrom(expArgType)) {
return am.getAnnotated();
}
}
}
}
return null;
}
{
/* First: return<SCANS> value serializer; but, alas, there's no access
* to serializer factory at this point...
*/
// let's cache it, may be needed soon again
ser = prov.findTypedValueSerializer(c, true, _property);
}
ser.serialize(value, gen, prov);
} catch (IOException ioe) {
throw ioe;
} catch (Exception e) {
Throwable t = e;
// Need to unwrap this specific type, to see infinite recursion...
while (t instanceof InvocationTargetException && t.getCause() != null) {
t = t.getCause();
}
// Errors shouldn't be wrapped (and often can't, as well)
if (t instanceof Error) {
throw (Error) t;
}
// let's try to indicate the path best we can...
throw JsonMappingException.wrapWithPath(t, bean, _accessorMethod.getName() + "()");
}
}
@Override
public void serializeWithType(Object bean, JsonGenerator gen, SerializerProvider provider,
TypeSerializer typeSer0) throws IOException
{
// Regardless of other parts, first need to find value to serialize:
Object value = null;
try {
value = _accessorMethod.getValue(bean);
// and if we got null, can also just write it directly
if (value == null) {
provider.defaultSerializeNull(gen);
return;
}
JsonSerializer<Object> ser = _valueSerializer;
if (ser == null) { // no serializer yet? Need to fetch
// ser = provider.findTypedValueSerializer(value.getClass(), true, _property);
ser = provider.findValueSerializer(value.getClass(), _property);
} else {
/* 09-Dec-2010, tatu: To work around natural type's refusal to add type info, we do
* this (note: type is for the wrapper type, not enclosed value!)
*/
if (_forceTypeInformation) {
typeSer0.writeTypePrefixForScalar(bean, gen);
ser.serialize(value, gen, provider);
typeSer0.writeTypeSuffixForScalar(bean, gen);
return;
}
}
// 28-Sep-2016, tatu: As per [databind#
JacksonDatabind, 65
<FILEB>
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: (%s) %s",
re.getClass().getName(), re.getMessage());
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
if (isFactoryMethod(am) && am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
if (am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
} else {
return null;
}
return new StdKeyDeserializer(kind, raw);
}
@Override
public Object deserializeKey(String key, DeserializationContext ctxt)
throws IOException
{
if (key == null) { // is this even legal call?
return null;
}
try {
Object result = _parse(key, ctxt);
if (result != null) {
return result;
}
} catch (Exception re) {
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: %s", re.getMessage());
<CHANGEE>
}
if (_keyClass.isEnum() && ctxt.getConfig().isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
return null;
}
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation");
}
public Class<?> getKeyClass() { return _keyClass; }
protected Object _parse(String key, DeserializationContext ctxt) throws Exception
{
switch (_kind) {
case TYPE_BOOLEAN:
if ("true".equals(key)) {
<FILEE>
<FILEB>
*/
if (ac.getParameterCount() == 1) {
Class<?> actArg = ac.getRawParameterType(0);
for (Class<?> expArg : argTypes) {
if (expArg == actArg) {
return ac.getAnnotated();
}
}
}
}
return null;
}
@Override
public Method findFactoryMethod(Class<?>... expArgTypes)
{
// So, of all single-arg static methods:
for (AnnotatedMethod am : _classInfo.getStaticMethods()) {
// 24-Oct-2016, tatu: Better ensure it only takes 1 arg, no matter what
<CHANGES>
if (isFactoryMethod(am)) {
<CHANGEE>
// And must take one of expected arg types (or supertype)
Class<?> actualArgType = am.getRawParameterType(0);
for (Class<?> expArgType : expArgTypes) {
// And one that matches what we would pass in
if (actualArgType.isAssignableFrom(expArgType)) {
return am.getAnnotated();
}
}
}
}
return null;
}
{
/* First: return<SCANS>package com.fasterxml.jackson.databind.deser.std;
import java.io.IOException;
import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.deser.BeanDeserializer;
import com.fasterxml.jackson.databind.deser.SettableBeanProperty;
import com.fasterxml.jackson.databind.util.NameTransformer;
/**
* Deserializer that builds on basic {@link BeanDeserializer} but
* override some aspects like instance construction.
*/
public class ThrowableDeserializer
extends BeanDeserializer
{
private static final long serialVersionUID = 1L;
protected final static String PROP_NAME_MESSAGE = "message";
/*
/************************************************************
/* Construction
/************************************************************
*/
public ThrowableDeserializer(BeanDeserializer baseDeserializer) {
super(baseDeserializer);
// need to disable this, since we do post-processing
_vanillaProcessing = false;
}
/**
* Alternative constructor used when creating "unwrapping" deserializers
*/
protected ThrowableDeserializer(BeanDeserializer src, NameTransformer unwrapper) {
super(src, unwrapper);
}
@Override
public JsonDeserializer<Object> unwrappingDeserializer(NameTransformer unwrapper) {
if (getClass() != ThrowableDeserializer.class) {
return this;
}
/* main thing really is to just enforce ignoring of unknown
* properties; since there may be multiple unwrapped values
* and properties for all may be interleaved...
*/
return new ThrowableDeserializer(this, unwrapper);
}
/*
/************************************************************
/* Overridden methods
/************************************************************
*/
@Override
public Object deserializeFromObject(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 30-Sep-2010, tatu: Need to allow use of @JsonCreator, so:
if (_propertyBasedCreator != null) { // proper @JsonCreator
return _deserializeUsingPropertyBased(p, ctxt);
}
if (_delegateDeserializer != null) {
return _valueInstantiator.createUsingDelegate(ctxt,
_delegateDeserializer.deserialize(p, ctxt));
}
if (_beanType.isAbstract()) { // for good measure, check this too
return ctxt.handleMissingInstantiator(handledType(), p,
"abstract type (
JacksonDatabind, 65
<FILEB>
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: (%s) %s",
re.getClass().getName(), re.getMessage());
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
if (isFactoryMethod(am) && am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
if (am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
} else {
return null;
}
return new StdKeyDeserializer(kind, raw);
}
@Override
public Object deserializeKey(String key, DeserializationContext ctxt)
throws IOException
{
if (key == null) { // is this even legal call?
return null;
}
try {
Object result = _parse(key, ctxt);
if (result != null) {
return result;
}
} catch (Exception re) {
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: %s", re.getMessage());
<CHANGEE>
}
if (_keyClass.isEnum() && ctxt.getConfig().isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
return null;
}
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation");
}
public Class<?> getKeyClass() { return _keyClass; }
protected Object _parse(String key, DeserializationContext ctxt) throws Exception
{
switch (_kind) {
case TYPE_BOOLEAN:
if ("true".equals(key)) {
<FILEE>
<FILEB>
*/
if (ac.getParameterCount() == 1) {
Class<?> actArg = ac.getRawParameterType(0);
for (Class<?> expArg : argTypes) {
if (expArg == actArg) {
return ac.getAnnotated();
}
}
}
}
return null;
}
@Override
public Method findFactoryMethod(Class<?>... expArgTypes)
{
// So, of all single-arg static methods:
for (AnnotatedMethod am : _classInfo.getStaticMethods()) {
// 24-Oct-2016, tatu: Better ensure it only takes 1 arg, no matter what
<CHANGES>
if (isFactoryMethod(am)) {
<CHANGEE>
// And must take one of expected arg types (or supertype)
Class<?> actualArgType = am.getRawParameterType(0);
for (Class<?> expArgType : expArgTypes) {
// And one that matches what we would pass in
if (actualArgType.isAssignableFrom(expArgType)) {
return am.getAnnotated();
}
}
}
}
return null;
}
{
/* First: return<SCANS>
return _children.values().iterator();
}
@Override
public JsonNode get(int index) { return null; }
@Override
public JsonNode get(String fieldName) {
return _children.get(fieldName);
}
@Override
public Iterator<String> fieldNames() {
return _children.keySet().iterator();
}
@Override
public JsonNode path(int index) {
return MissingNode.getInstance();
}
@Override
public JsonNode path(String fieldName)
{
JsonNode n = _children.get(fieldName);
if (n != null) {
return n;
}
return MissingNode.getInstance();
}
/**
* Method to use for accessing all fields (with both names
* and values) of this JSON Object.
*/
@Override
public Iterator<Map.Entry<String, JsonNode>> fields() {
return _children.entrySet().iterator();
}
@Override
public ObjectNode with(String propertyName) {
JsonNode n = _children.get(propertyName);
if (n != null) {
if (n instanceof ObjectNode) {
return (ObjectNode) n;
}
throw new UnsupportedOperationException("Property '" + propertyName
+ "' has value that is not of type ObjectNode (but " + n
.getClass().getName() + ")");
}
ObjectNode result = objectNode();
_children.put(propertyName, result);
return result;
}
@Override
public ArrayNode withArray(String propertyName)
{
JsonNode n = _children.get(propertyName);
if (n != null) {
if (n instanceof ArrayNode) {
return (ArrayNode) n;
}
throw new UnsupportedOperationException("Property '" + propertyName
+ "' has value that is not of type ArrayNode (but " + n
.getClass().getName() + ")");
}
ArrayNode result = arrayNode();
_children.put(propertyName, result);
return result;
}
@Override
public boolean equals(Comparator<JsonNode> comparator, JsonNode o)
{
if (!(o instanceof ObjectNode)) {
return false;
}
ObjectNode other = (ObjectNode) o;
Map<String, JsonNode> m1 = _children;
Map<String, JsonNode> m2 = other._children;
final int len = m1.size();
if (m2
JacksonDatabind, 65
<FILEB>
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: (%s) %s",
re.getClass().getName(), re.getMessage());
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
if (isFactoryMethod(am) && am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
if (am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
} else {
return null;
}
return new StdKeyDeserializer(kind, raw);
}
@Override
public Object deserializeKey(String key, DeserializationContext ctxt)
throws IOException
{
if (key == null) { // is this even legal call?
return null;
}
try {
Object result = _parse(key, ctxt);
if (result != null) {
return result;
}
} catch (Exception re) {
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: %s", re.getMessage());
<CHANGEE>
}
if (_keyClass.isEnum() && ctxt.getConfig().isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
return null;
}
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation");
}
public Class<?> getKeyClass() { return _keyClass; }
protected Object _parse(String key, DeserializationContext ctxt) throws Exception
{
switch (_kind) {
case TYPE_BOOLEAN:
if ("true".equals(key)) {
<FILEE>
<FILEB>
*/
if (ac.getParameterCount() == 1) {
Class<?> actArg = ac.getRawParameterType(0);
for (Class<?> expArg : argTypes) {
if (expArg == actArg) {
return ac.getAnnotated();
}
}
}
}
return null;
}
@Override
public Method findFactoryMethod(Class<?>... expArgTypes)
{
// So, of all single-arg static methods:
for (AnnotatedMethod am : _classInfo.getStaticMethods()) {
// 24-Oct-2016, tatu: Better ensure it only takes 1 arg, no matter what
<CHANGES>
if (isFactoryMethod(am)) {
<CHANGEE>
// And must take one of expected arg types (or supertype)
Class<?> actualArgType = am.getRawParameterType(0);
for (Class<?> expArgType : expArgTypes) {
// And one that matches what we would pass in
if (actualArgType.isAssignableFrom(expArgType)) {
return am.getAnnotated();
}
}
}
}
return null;
}
{
/* First: return<SCANS>
gen.writeNumber((Short) n);
} else {
gen.writeNumber(((Number) n).intValue());
}
}
break;
case VALUE_NUMBER_FLOAT:
{
Object n = segment.get(ptr);
if (n instanceof Double) {
gen.writeNumber(((Double) n).doubleValue());
} else if (n instanceof BigDecimal) {
gen.writeNumber((BigDecimal) n);
} else if (n instanceof Float) {
gen.writeNumber(((Float) n).floatValue());
} else if (n == null) {
gen.writeNull();
} else if (n instanceof String) {
gen.writeNumber((String) n);
} else {
throw new JsonGenerationException(String.format(
"Unrecognized value type for VALUE_NUMBER_FLOAT: %s, can not serialize",
n.getClass().getName()), gen);
}
}
break;
case VALUE_TRUE:
gen.writeBoolean(true);
break;
case VALUE_FALSE:
gen.writeBoolean(false);
break;
case VALUE_NULL:
gen.writeNull();
break;
case VALUE_EMBEDDED_OBJECT:
{
Object value = segment.get(ptr);
// 01-Sep-2016, tatu: as per [databind#1361], should use `writeEmbeddedObject()`;
// however, may need to consider alternatives for some well-known types
// first
if (value instanceof RawValue) {
((RawValue) value).serialize(gen);
} else if (value instanceof JsonSerializable) {
gen.writeObject(value);
} else {
gen.writeEmbeddedObject(value);
}
}
break;
default:
throw new RuntimeException("Internal error: should never end up through this code path");
}
}
}
/**
* Helper method used by standard deserializer.
*
* @since 2.3
*/
public TokenBuffer deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
if (p.getCurrentTokenId() != JsonToken.FIELD_NAME.id()) {
copyCurrentStructure(p);
return this;
}
/* 28-Oct-2014, tatu: As per [databind#
JacksonDatabind, 65
<FILEB>
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: (%s) %s",
re.getClass().getName(), re.getMessage());
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
if (isFactoryMethod(am) && am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
if (am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
} else {
return null;
}
return new StdKeyDeserializer(kind, raw);
}
@Override
public Object deserializeKey(String key, DeserializationContext ctxt)
throws IOException
{
if (key == null) { // is this even legal call?
return null;
}
try {
Object result = _parse(key, ctxt);
if (result != null) {
return result;
}
} catch (Exception re) {
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: %s", re.getMessage());
<CHANGEE>
}
if (_keyClass.isEnum() && ctxt.getConfig().isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
return null;
}
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation");
}
public Class<?> getKeyClass() { return _keyClass; }
protected Object _parse(String key, DeserializationContext ctxt) throws Exception
{
switch (_kind) {
case TYPE_BOOLEAN:
if ("true".equals(key)) {
<FILEE>
<FILEB>
*/
if (ac.getParameterCount() == 1) {
Class<?> actArg = ac.getRawParameterType(0);
for (Class<?> expArg : argTypes) {
if (expArg == actArg) {
return ac.getAnnotated();
}
}
}
}
return null;
}
@Override
public Method findFactoryMethod(Class<?>... expArgTypes)
{
// So, of all single-arg static methods:
for (AnnotatedMethod am : _classInfo.getStaticMethods()) {
// 24-Oct-2016, tatu: Better ensure it only takes 1 arg, no matter what
<CHANGES>
if (isFactoryMethod(am)) {
<CHANGEE>
// And must take one of expected arg types (or supertype)
Class<?> actualArgType = am.getRawParameterType(0);
for (Class<?> expArgType : expArgTypes) {
// And one that matches what we would pass in
if (actualArgType.isAssignableFrom(expArgType)) {
return am.getAnnotated();
}
}
}
}
return null;
}
{
/* First: return<SCANS>value == null) {
writeNull();
return;
}
Class<?> raw = value.getClass();
if (raw == byte[].class || (value instanceof RawValue)) {
_appendValue(JsonToken.VALUE_EMBEDDED_OBJECT, value);
return;
}
if (_objectCodec == null) {
/* 28-May-2014, tatu: Tricky choice here; if no codec, should we
* err out, or just embed? For now, do latter.
*/
// throw new JsonMappingException("No ObjectCodec configured for TokenBuffer, writeObject() called");
_appendValue(JsonToken.VALUE_EMBEDDED_OBJECT, value);
} else {
_objectCodec.writeValue(this, value);
}
}
@Override
public void writeTree(TreeNode node) throws IOException
{
if (node == null) {
writeNull();
return;
}
if (_objectCodec == null) {
// as with 'writeObject()', is codec optional?
_appendValue(JsonToken.VALUE_EMBEDDED_OBJECT, node);
} else {
_objectCodec.writeTree(this, node);
}
}
/*
/***********************************************************
/* JsonGenerator implementation; binary
/***********************************************************
*/
@Override
public void writeBinary(Base64Variant b64variant, byte[] data, int offset, int len) throws IOException
{
/* 31-Dec-2009, tatu: can do this using multiple alternatives; but for
* now, let's try to limit number of conversions.
* The only (?) tricky thing is that of whether to preserve variant,
* seems pointless, so let's not worry about it unless there's some
* compelling reason to.
*/
byte[] copy = new byte[len];
System.arraycopy(data, offset, copy, 0, len);
writeObject(copy);
}
/**
* Although we could support this method, it does not necessarily make
* sense: we can not make good use of streaming because buffer must
* hold all the data. Because of this, currently this will simply
* throw {@link UnsupportedOperationException}
*/
@Override
public int writeBinary(Base64Variant b64variant,
JacksonDatabind, 65
<FILEB>
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: (%s) %s",
re.getClass().getName(), re.getMessage());
<CHANGEE>
<FILEE>
<FILEB>
<CHANGES>
if (isFactoryMethod(am) && am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
if (am.getParameterCount() == 1) {
<CHANGEE>
<CHANGES>
}
<CHANGEE>
<FILEE>
<FILEB>
} else {
return null;
}
return new StdKeyDeserializer(kind, raw);
}
@Override
public Object deserializeKey(String key, DeserializationContext ctxt)
throws IOException
{
if (key == null) { // is this even legal call?
return null;
}
try {
Object result = _parse(key, ctxt);
if (result != null) {
return result;
}
} catch (Exception re) {
<CHANGES>
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: %s", re.getMessage());
<CHANGEE>
}
if (_keyClass.isEnum() && ctxt.getConfig().isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
return null;
}
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation");
}
public Class<?> getKeyClass() { return _keyClass; }
protected Object _parse(String key, DeserializationContext ctxt) throws Exception
{
switch (_kind) {
case TYPE_BOOLEAN:
if ("true".equals(key)) {
<FILEE>
<FILEB>
*/
if (ac.getParameterCount() == 1) {
Class<?> actArg = ac.getRawParameterType(0);
for (Class<?> expArg : argTypes) {
if (expArg == actArg) {
return ac.getAnnotated();
}
}
}
}
return null;
}
@Override
public Method findFactoryMethod(Class<?>... expArgTypes)
{
// So, of all single-arg static methods:
for (AnnotatedMethod am : _classInfo.getStaticMethods()) {
// 24-Oct-2016, tatu: Better ensure it only takes 1 arg, no matter what
<CHANGES>
if (isFactoryMethod(am)) {
<CHANGEE>
// And must take one of expected arg types (or supertype)
Class<?> actualArgType = am.getRawParameterType(0);
for (Class<?> expArgType : expArgTypes) {
// And one that matches what we would pass in
if (actualArgType.isAssignableFrom(expArgType)) {
return am.getAnnotated();
}
}
}
}
return null;
}
{
/* First: return<SCANS>
}
@Override
public double getDoubleValue() throws IOException {
return getNumberValue().doubleValue();
}
@Override
public float getFloatValue() throws IOException {
return getNumberValue().floatValue();
}
@Override
public int getIntValue() throws IOException
{
// optimize common case:
if (_currToken == JsonToken.VALUE_NUMBER_INT) {
return ((Number) _currentObject()).intValue();
}
return getNumberValue().intValue();
}
@Override
public long getLongValue() throws IOException {
return getNumberValue().longValue();
}
@Override
public NumberType getNumberType() throws IOException
{
Number n = getNumberValue();
if (n instanceof Integer) return NumberType.INT;
if (n instanceof Long) return NumberType.LONG;
if (n instanceof Double) return NumberType.DOUBLE;
if (n instanceof BigDecimal) return NumberType.BIG_DECIMAL;
if (n instanceof BigInteger) return NumberType.BIG_INTEGER;
if (n instanceof Float) return NumberType.FLOAT;
if (n instanceof Short) return NumberType.INT; // should be SHORT
return null;
}
@Override
public final Number getNumberValue() throws IOException {
_checkIsNumber();
Object value = _currentObject();
if (value instanceof Number) {
return (Number) value;
}
// Difficult to really support numbers-as-Strings; but let's try.
// NOTE: no access to DeserializationConfig, unfortunately, so can not
// try to determine Double/BigDecimal preference...
if (value instanceof String) {
String str = (String) value;
if (str.indexOf('.') >= 0) {
return Double.parseDouble(str);
}
return Long.parseLong(str);
}
if (value == null) {
return null;
}
throw new IllegalStateException("Internal error: entry should be a Number, but is of type "
+value.getClass().getName());
}
/*
/**********************************************************
/* Public API, access to token information, other
/**********************************************************
*/
@Override
public Object getEmbeddedObject()
{
if (_currToken == JsonToken.VALUE_EMBEDDED_OBJECT) {
return _currentObject();
}
return null;